Docker container doesn't expose ports when –net=host is mentioned in the docker run command

I have a CentOS docker container on a CentOS docker host. When I use this command to run the docker image docker run -d --net=host -p 8777:8777 ceilometer:1.x the docker container get host’s IP but doesn’t have ports assigned to it.

If I run the same command without “–net=host” docker run -d -p 8777:8777 ceilometer:1.x docker exposes the ports but with a different IP. The docker version is 1.10.1. I want the docker container to have the same IP as the host with ports exposed. I also have mentioned in the Dockerfile the instruction EXPOSE 8777 but with no use when “–net=host” is mentioned in the docker run command.

  • Setting up jenkins with docker and bundler
  • Executing `ls` on docker with a shared volume results in “No such file or directory”
  • Docker: RVM command not found
  • How do I build docker images when my development environment mounts my codebase into the container?
  • What is a simple workflow to use docker in Windows with a basic file sharing possibility?
  • Where do Docker containers COPY files inside a container?
  • Docker for windows10 run django fail: Can't open file 'manage.py': [Errno 2] No such file or directory
  • Why do containers fail to fetch URIs in DC/OS?
  • Accessing the number of arguments pass into a docker run command script
  • Save docker-compose logs to a file
  • Change Jeninks build status on specific error
  • Docker - exposing IP addresses to DNS server
  • One Solution collect form web for “Docker container doesn't expose ports when –net=host is mentioned in the docker run command”

    The docker version is 1.10.1. I want the docker container to have same ip as the host with ports exposed.

    When you use --net=host it tells the container to use the hosts networking stack. So you can’t expose ports to the host, because it is the host (as far as the network stack is concerned).

    docker inspect might not show the expose ports, but if you have an application listening on a port, it will be available as if it were running on the host.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.