Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to assign network and binding ports to a docker agent in Jenkins?

I have the next setup:

  • one amazon EC2 instance;
  • Jenkins installed on it;
  • Docker instance installed along with Jenkins

When I am starting the container (in a pipeline script) I am trying to add also the host network and also binding ports.

node {
    docker.image('localhost:5000/build_deploy_agent:base').withRun('-t --network host -p 9101:9101') { c ->
        sh 'doing stuff'
    }
}

I need this because at the end I want to keep the container alive with the deployed application.

The problem is, no network or ports are assigned to the container. Only the -t command is taken in consideration.

enter image description here

Is there a way to do this or I am losing time?

like image 658
Cristian M Avatar asked Nov 20 '25 07:11

Cristian M


1 Answers

Check first if the network is visible through inspection, instead of just docker ps.
See "How to find the network my container is in?"

docker inspect <lyContainer> -f "{{json .NetworkSettings.Networks }}"

Or you could filter docker ps by network, again, to check if the containers were assigned to the expected network.

You can also check your network stack through a Jenkins step like ip addr show to see if a new network interface was created.

like image 198
VonC Avatar answered Nov 22 '25 03:11

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!