Publish to random host port while using –network=host

I am trying to access a host URL from within a docker container. I would also like to publish container ports to random ports on the host.

docker run --network=host -P -d somerepo/someimage

However, it looks like the -P and the --net=host options don’t want to co-exist as I don’t see any port mappings created when I run a docker ports <container_id>

  • can't connect to docker container from outside
  • How does one get docker running on Ubuntu 16 and remove old installs?
  • How can I set the current working directory for docker exec with an internal bash shell?
  • Can we use docker-image with the hyperkit driver on a mac?
  • What is the optimal way to store data-files for testing using travis-ci + Docker?
  • Mount host directory with a symbolic link inside in docker container
  • Am I missing something obvious here?

    PS: There is no docker-machine involved. Docker engine is running directly on the host machine.

  • Copy files from host to docker container then commit and push
  • How to continue using docker container after startup application exit?
  • How can I fix the permissions using docker on a bluemix volume?
  • docker 1.12 swarm cluster cannot serve static files
  • Command to move folders from one container to another container using Dockerfile
  • How do I limit a volume's size using the API?
  • One Solution collect form web for “Publish to random host port while using –network=host”

    You can’t use -P or -p with --net=host because that doesn’t make any sense. When you’re using --net=host, IF a process in a container opens a port THEN that port is open on your host. No mapping is required, because your container process are running in the host’s network environment.

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