Regarding Docker Container Port

I am new to docker and I have been trying to bind different ports to ports in containers.

For example: Docker getting/started container if I run using -p 5000:80 then it works properly. However if I change 80 to any thing else then i am not able to access the running container. What exactly is the issue here?

I am using WSL v2 with Docker On Windows Home

Hi

In the container, a service is running, that listens on a port, that port is either default for the software running, or defined by the creator of the image.

In this case, a normal webserver is running on its default port, port 80 so you cant change that without making changes to the image/configuration within the image.

in your case “-p 5000:80”
means that port 5000 on your host, is mapped to port 80 in the container, you can change your port 5000 to anything you want, but in this case, “80” needs to be the same, else you are saying “i want to access the service in this container on port 8080(example)” but no service is running on port 8080

1 Like