Sobes.tech
Junior — Middle

How can a Docker container port be made accessible from an external network?

sobes.tech AI

Answer from AI

To make a Docker container port accessible from an external network, you need to use the -p or --publish option when running the container, which forwards the port from the container to the host machine. The command format:

docker run -p <host_port>:<container_port> <image>

For example, if the application inside the container listens on port 80, and you want it to be accessible on port 8080 of the host:

docker run -p 8080:80 myimage

After that, the application can be accessed at http://<host_IP>:8080. If the host is accessible from an external network, then the container will also be accessible through this port.

It is important to ensure that the firewall and network settings of the host allow incoming connections on the specified port.