Basic Dockerfiles

Docker lets you create and run containers. Containers are similar to Virtual Machines but use less resources. They are less secure than VMs.

Docker creates containers from images. You can create a docker image using a Dockerfile. This file contains the following:

  1. Which docker image to use as a base for the new image.
  2. Any files that need to be copied into the container.
  3. Commands to setup the docker container.
  4. A single command to run when the container starts.


# Dockerfile
FROM python

COPY . /app


RUN pip install -r /app/requirements.txt


CMD waitress-serve --listen=*:5000 wsgi:application

The above is a simple example to run a python webserver:

  1. Uses the official python image as a base
  2. Copies everything in the current folder into /app in our container
  3. Sets /app as the folder to run commands in
  4. Installs dependencies via pip
  5. Says that container runs something on port 5000
  6. Tells docker to run a waitress server when the container starts


Each line of a Dockerfile is a command, there are many different commands but these are some of the most common.

the docker image to base the new image on
the directory to run any commands in
copy files or folders into the container
a shell command to help setup the container
the shell command to run when the container is started
any ports the container wants to expose