Docker#

Setup#

You require a working Docker engine installed on your computer if you would like to experience working with containers.

Docker Desktop can be downloaded and install from here.

Problems? Follow the extensive installation guide from Docker

On successful installation, please verify your installation with docker run hello-world from your command line. You will see the “Hello from Docker!” message.

Note

For Windows machines, Hyper-V and WSL should be enabled to run the Docker engine. Also, you need virtualization support enabled in the BIOS.

Dockerfile#

Docker runs instructions in a Dockerfile to build an image. An example docker script on running a python image:

FROM python:latest

COPY requirements.txt ./
RUN python3 -m pip install -r requirements.txt

The above script firstly loads the latest python image from DockerHub as a base image using the FROM <IMAGENAME> statement. Then the Dockerfile asks to copy a file requirements.txt in the build directory containing a list of required python packages is copied while building. With the RUN statement, python3-pip installs the desired packages.

For more information on writing a Dockerfile, please refer to https://docs.docker.com/engine/reference/builder/.

Building an Image#

To build an image follow the following script:

docker build . -t name_of_docker_image:version

Running a Container#

With docker run IMAGE_NAME, one can run the above docker image. If you would like to open an interactive bash within the container, use:

docker run -it name_of_docker_image:version