Sitemap
Benjamin Aguilar

Benjamin Aguilar

I’m a software developer with more than 10 years of working for companies located in different countries using Java, Python, Django, PHP, Laravel.

Docker Python Hello World

2 min readApr 24, 2022

Prerequisites

  • VSCode
  • Docker extension
  • Python
  • Docker Desktop
  1. 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.

Press enter or click to view image in full size

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.

--

--

Benjamin Aguilar
Benjamin Aguilar

Written by Benjamin Aguilar

I’m a software developer with more than 10 years of working for companies located in different countries using Java, Python, Django, PHP, Laravel.