Your Dockerfile already builds an image with Python, the shop's packages and its code in /app. But an image only says what is inside it. It must also say how the app starts: EXPOSE notes the port the app listens on, and CMD is the command a container runs when it starts.
Write CMD as a JSON list: each word in double quotes, separated by commas, inside [ ]. Docker then starts the program directly, not through a shell, so the stop signal of docker stop reaches it. For another app, a small server on port 5000, it would look like this:
EXPOSE 5000
CMD ["python", "server.py"]
A container has its own network. Inside it, 127.0.0.1 is the container itself, so a server in a container must listen on 0.0.0.0. To reach it from your computer, docker run -p publishes a port, your computer's port first, then the container's: -p 9000:5000 sends your computer's port 9000 to the container's port 5000.
When your code is done, the check prints:
$ docker build -t shop . The image: Python 3.13, the packages and the shop in /app EXPOSE 8000: the app listens on port 8000 in the container (a note for whoever runs the image, it opens nothing by itself) CMD: when the container starts, it runs gunicorn --bind 0.0.0.0:8000 --workers 2 app:app JSON list form: gunicorn is the main process of the container, so the stop signal of docker stop reaches it In the container: gunicorn listens on 0.0.0.0:8000 and runs app:app from /app $ docker run -p 8000:8000 shop -p 8000:8000: port 8000 of your computer goes to port 8000 of the container http://localhost:8000/ -> port 8000 of the container -> gunicorn -> app.py: the shop answers
Your task: add two lines to the dockerfile string: EXPOSE 8000, and a CMD that runs gunicorn as a JSON list (bind 0.0.0.0:8000, 2 workers, app:app). Then, below it, store the command that starts a container from the image shop in the string run_command.
Assignment
Follow the Coding Tutorial to add the EXPOSE and CMD lines to the Dockerfile and write the docker run command.
Hint
The CMD line has double quotes inside, so write that piece of the Python string between single quotes. In -p, your computer's port comes first, then the container's.
Free plan: 30 tutor messages. PRO is unlimited.
