Using either EXPOSE or -publish to access the container on the bridge network will not accomplish the goal of creating a container that is reachable from its host’s network. EXPOSE is a way of documenting which ports a container listens on, but it does not open any ports to the host1. -publish (or -p) is a way of mapping a host port to a container port, but it does not change the network mode of the container2. By default, Docker containers use the bridge network, which isolates them from the host network3. To create a container that is reachable from its host’s network, you need to usethe --network host option when running the container4. This will make the container share the host’s network stack and have the same IP address as the host4. References:
1: Difference Between “expose” and “publish” in Docker | Baeldung on Ops
2: Deploy services to a swarm | Docker Docs
3: Bridge network | Docker Docs
4: Host network | Docker Docs
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit