Sign in

This Will Make Your Software Easier to Build, Run, and Distribute

Say goodbye to those hard-to-build software projects by containerizing them

Image for post
Image for post
Photo by Lucas van Oort on Unsplash

What is a container?

Image for post
Image for post
Multiple containers running next to each other (source)

Containers make it easy to package and ship your software and provide a well-defined environment for it to run in.

What is an image?

Image for post
Image for post
Multiple layers make up a container (image by author)

How to containerize your software

packages]
Flask = "*"
print("Hello world")
FROM python:3WORKDIR /usr/src/app
COPY Pipfile ./
RUN pip install --no-cache-dir pipenv && pipenv install
COPY *.py .
CMD [ "python", "./app.py" ]
C:\dev\python-docker> docker build -t my_webservice .
Image for post
Image for post
Docker is downloading all layers of the Python container. Image © by author.
PS C:\dev\python-docker> docker run my_webservice
Hello world
PS C:\dev\python-docker>

Improving our container

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
CMD [ "pipenv", "run", "python", "-m", "flask", "run", "--host=0.0.0.0" ]
C:\dev\python-docker> docker build -t my_webservice .
C:\dev\python-docker> docker run -p 5000:5000 my_webservice 
* Environment: production
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Written by

Software developer by day, writer at night. Author of python3.guide, where you can start learning Python today

Sign up for Tech Explained

By Programming with Erik

Short, low-volume newsletter to keep you up-to-date on my latest articles Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store