3

I am building a docker image and running it will following command:

docker run --name myjenkins -u root -d -p 8080:8080 -p 50000:50000 -v jenkins-volume:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --net=host vm31

docker container is up and running when i do docker ps output is :

CONTAINER ID        IMAGE                                                                              COMMAND                  CREATED             STATUS              PORTS                                                                                        NAMES
22a92a3b7875        vm31                                                                              "/sbin/tini -- /usr/…"   4 seconds ago       Up 3 seconds     

why does not it show the port on which this container is running - so i can not reach jenkins on localhost:8080

vm31
  • 169
  • 1
  • 4
  • 15
  • Is you container running or restarting? check ` STATUS` columns – Ntwobike Oct 04 '18 at 09:03
  • @Ntwobike yes my container status is up as shown in my question and created 4 seconds ago – vm31 Oct 04 '18 at 09:05
  • check `docker inspect container-id` and the `NetworkSettings` – Ntwobike Oct 04 '18 at 09:13
  • 1
    Possible duplicate of [Docker container doesn't expose ports when --net=host is mentioned in the docker run command](https://stackoverflow.com/questions/35586778/docker-container-doesnt-expose-ports-when-net-host-is-mentioned-in-the-docker) – tgogos Oct 04 '18 at 09:51

2 Answers2

4

You are using two conflicting things together:

  • --net=host
  • -p 8080:8080 -p 50000:50000

The first tells the container to use the network stack of the host, the second is the way to bind container ports with host ports. I believe you only want to use the second one.

tgogos
  • 23,218
  • 20
  • 96
  • 128
  • myjenkins is a docker container that has docker in it so I had to run it with --net=host – vm31 Oct 04 '18 at 09:43
  • Ok, this means that you don't have to `publish` any port then. Any active port of your container will be bound to the same port of the host. – tgogos Oct 04 '18 at 09:45
  • but i had it working before few days having these two together in docker run i want net=host if not rabbitmq will never be reachable – vm31 Oct 04 '18 at 10:10
  • What I meant in my previous comment is: (1) it's ok to keep `--net=host` (2) remove the `-p 8080:8080 -p 50000:50000` – tgogos Oct 04 '18 at 10:31
2

try after removing option --net=host.

  • when i take --net=host it is working but my application is a set of container that will not be reachable without rabbitmq that will not be reachable without --net=host – vm31 Oct 04 '18 at 10:17
  • --net=host means you are using host network and you publish port will not work. https://docs.docker.com/network/network-tutorial-host/#goal – Virendar Kumar Oct 04 '18 at 12:42