3

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?

Cristian M
  • 357
  • 1
  • 3
  • 18

1 Answers1

2

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you and I sorry for the delay in replying to you. In fact I checked the network of my opened containers right before I saw your answer, and I realized that this is a very stupid question (you cannot have a container running with 'host' network and binding ports setup. Docker throws an error). I have tried it before directly with docker, and started two containers on the 'host' network with biding ports. For some weird reason this worked. When I checked the networks, both containers were started with 'bridge' connection, and this is why the connection with the host was running OK. – Cristian M Feb 28 '21 at 06:31