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:
- Which docker image to use as a base for the new image.
- Any files that need to be copied into the container.
- Commands to setup the docker container.
- A single command to run when the container starts.
# Dockerfile FROM python COPY . /app WORKDIR /app RUN pip install -r /app/requirements.txt EXPOSE 5000 CMD waitress-serve --listen=*:5000 wsgi:application
The above is a simple example to run a python webserver:
- Uses the official python image as a base
- Copies everything in the current folder into
/appin our container
/appas the folder to run commands in
- Installs dependencies via pip
- Says that container runs something on port
- 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