简体   繁体   中英

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>

Am I missing something obvious here?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM