Docker已发布端口被丢弃后如何设置端口?TensorFlow容器端口配置求助
Hey there! Let's break down that warning and get your TensorFlow GPU container working with the port setup you need.
The message "WARNING: Published ports are discarded when using host network mode" tells us one key thing: your Docker container is running in host network mode. In this mode, the container shares your host machine's entire network stack—so any port mappings you try to set with -p get ignored. The container can already reach all ports on your host directly, so Docker doesn't bother applying the mapping.
Chances are, either you accidentally added a --network=host flag in a previous run, or there's a default config setting that's enabling host mode without you noticing.
If you don't have a specific reason to use host network mode, this is the easiest fix. Just make sure your command doesn't include --network=host, and re-run your original command:
docker run --runtime=nvidia --name tensorflow3 -it -p 6006:6006 tensorflow/tensorflow:latest-gpu-py3-jupyter
This will use Docker's default bridge network, and the -p 6006:6006 mapping will work as expected. You'll be able to access Jupyter or TensorBoard at http://localhost:6006 once the container is up and running.
If you're using host mode for a specific reason (like better network performance or access to host-specific network services), you don't need to specify any port mappings at all. Since the container shares your host's network, you can access its services directly using your host's IP or localhost on port 6006. Just run the command without the -p flag:
docker run --runtime=nvidia --name tensorflow3 -it --network=host tensorflow/tensorflow:latest-gpu-py3-jupyter
Then point your browser to http://localhost:6006—no extra mapping needed.
To confirm what network mode your container is running in, run this quick command:
docker inspect tensorflow3 | grep -i networkmode
It will output either host or bridge (the default), so you'll know exactly what's going on.
内容的提问来源于stack exchange,提问作者andy

