How Do You Access the Networking Port of a Docker Container When There Appears to Be No Port Mapping, Just a Single Port Exposed by Itself?

Problem scenario
You run "docker ps -a" and see values in the PORTS column.  You see values such as these for two separate containers:

Container 1 has this:  0.0.0.0:32775->5000/tcp

Container 2 has this:  5731/tcp

You cannot reach the containers that have no "->" symbol in them via web browsers or other network connectivity tools.  You can reach those containers with the "->" symbol in the PORTS value.  What is wrong with the Docker containers with only one TCP port and not "->" syntax?

Solution
Those containers with no "->" mapping symbol in the PORTS value in the results of a "docker ps -a" command were potentially created without a necessary flag.  The "-P" option may be enough to get them to work properly.

For creating a container with a TCP port that will be exposed, use this command (with a known working Docker image):

docker create -it -P <image ID>

Alternatively you can use the "docker run" command to create and start a Docker container.  Here is the syntax for doing that with a known good image to create a container with a TCP port that will be exposed:

docker run -d -P <image ID>

Leave a comment

Your email address will not be published.