Example of Running Container Code in Python with Exposed Docker Port

Two pieces of information that you need:
The IP address of the container
The external port that docker exports this 9000 to the outside (by default docker does not export locally open ports).
Try with the flag
, like:
But before running try to check if there is something else that already running on the specified port like:
and after with something like:
Solution 2:
Make sure you’re mapping your localhost port to the container’s port
docker run -p your_image

Solution 1:

Simply designating a port as “exposed” does not result in the port being published. To achieve this, you can use the flag “-p”, for instance:

-p container_port:local_port


docker run -p 8080:8080 -v ~/Code/PYTHON/ttftt-recipes-manager:/app python_dev

Prior to executing, make sure to verify if any other process is already active on the designated port.

lsof -i :PORTNUM 

and after with something like:

docker logs my_container

Solution 2:

Ensure that you are connecting the port on your localhost to the corresponding port on the container.

Run your image with Docker on port 8000 by using the command “docker run -p your_image”.

After placing your application in the container, make sure to execute it by setting the host to

Frequently Asked Questions