Docker Python Hello World
Prerequisites
- VSCode
- Docker extension
- Python
- Docker Desktop
- Let’s create a helloworld.py file to start.
2. Enter the following code into the helloworld.py file and save it [ctrl+s]:
msg = "Hello World using Python & Docker"
print(msg)3. Run helloworld.py
And that’s it. You have a Python application ready to be containerized. :)
Get Benjamin Aguilar’s stories in your inbox
Join Medium for free to get updates from this writer.
4. Now we’re going to include the Dockerfile in our workspace. To do so, open the Command Palette [Ctrl+Shift+p] and type docker add, select Docker: Add Docker Files to Workspace…
5. Select Python: General.
6. Select helloworld.py as the app’s entry point.
7. Select No in the following prompt since we don’t need the Docker Compose file in this example.
It will create some files that are needed for Docker.
.dockerignore: for reducing the image size.
Dockerfile: build instructions for building the image.
requirements.txt: file to specify required packages/dependencies.
8. Now, we are ready to build and run our image.
You should get the message printed in the Debug Console.
And that’s it. You have successfully created a Docker image with a Python Hello World application.








