paint-brush
How to Use Docker with Python in Just 10 Minutesby@morganpage
1,307 reads
1,307 reads

How to Use Docker with Python in Just 10 Minutes

by MorganJuly 15th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How to Use Docker with Python in Just 10 Minutes is easy to do in just 10 minutes. Run Docker image build -t hello-world to create an image tagged 'hello-world' The new image is based on the official python:3.8-slim-buster image, has its working directory set to, has both files copied into this directory, and its default executable set to ‘python app.py’ The Dockerfile will use the Dockerfile to create a. repository name ofusing the current working directory of your project.
featured image - How to Use Docker with Python in Just 10 Minutes
Morgan HackerNoon profile picture

Sometimes you just want to dip your toe into a potentially deep and complex subject. Maybe you only have 10 minutes to spare and you want to get something up and running quickly.

In just 10 minutes, you will be able to say: ‘Oh yes, I’ve used Docker with Python’.

Install Docker

This is as simple as going to: https://www.docker.com/get-started, downloading, and running the installer for your system.

One Folder, Two Files

Open up a terminal window and create a folder for your project:

$ mkdir hello-world
$ cd hello-world

In your favorite editor create two files (app.py & Dockerfile) in this folder:

and

Now in the terminal type:

$ docker image build -t hello-world .

This will use the Dockerfile to create an image tagged

-t
with a repository name of
hello-world
using the current working directory
.
. The new image is based on the official python:3.8-slim-buster image, has its working directory set to
/usr/src/app
, has both files copied into this directory, and its default executable set to ‘python app.py’.

Now, all we need to do is run the image:

$ docker run hello-world

Which should give an output:

Hello World

Congratulations you have just used Docker with Python!

Also published here.