Installing docker

Last updated on 2024-06-25 | Edit this page

Estimated time: 35 minutes

Overview

Questions

  • How do you install Docker?
  • What are the main Docker concepts and commands I need to know?

Objectives

  • Install Docker
  • Test the installation
  • Learn and exercise the basic commands.

Installing docker


Go to the offical Docker site and their installation instructions to install Docker for your operating system.

For our purposes, we need docker-engine which is a free open-source software. Note that you can choose to install Docker Desktop (free for single, non-commercial use), but in our instructions, we do not rely on the Graphical UI that it offers.

Windows users:

In the episodes of this lesson that follow, we assume that Windows users have WSL2 activated with a Linux bash shell (e.g. Ubuntu). All commands indicated with “bash” are expected to be typed in this Linux shell (not in git bash or power shell).

Testing


As you walk through their documentation, you will eventually come to a point where you will run a very simple test, usually involving their hello-world container.

You can find their documentation for this step here.

Testing their code can be summed up by the ability to run (without generating any errors) the following commands.

BASH

docker --version

BASH

docker run hello-world

Important: Docker postinstall to avoid sudo for Linux installation

If you need sudo to run the command above, make sure to complete these steps after installations, otherwise you will run into trouble with shared file access later on. Guaranteed!!

In brief:

BASH

sudo groupadd docker #most likely exists already
sudo usermod -aG docker $USER

Then close the shell and open a new one. Verify that you can run docker run hello-world without sudo.

Images and Containers


As it was mentioned above, there is ample documentation provided by Docker official sites. However, there are a couple of concepts that are crucial for the sake of using the container technology with CMS open data: container images and containers.

One can think of the container image as the main ingredients for preparing a dish, and the final dish as the container itself. You can prepare many dishes (containers) based on the same ingredients (container image). Images can exist without containers, whereas a container needs to run an image to exist. Therefore, containers are dependent on images and use them to construct a run-time environment and run an application.

The final dish, for us, is a container that can be thought of as an isolated machine (running on the host machine) with mostly its own operating system and the adequate software and run-time environment to process CMS open data.

Docker provides the ability to create, build and/or modify images, which can then be used to create containers. For the MC generator, ML learning and CMS open data lessons, we will use already-built and ready-to-use images in order to create our needed container, but we will exercise building images with some additional code later on during the Midsummer QCD school hands-on sessions.

Commands Cheatsheet


There are many Docker commands that can be executed for different tasks. However, the most useful for our purposes are the following. We will show some usage examples for some of these commands later. Feel free to explore other commands.

Download image:

BASH

docker pull <image>

List images:

BASH

docker image ls

Remove images

BASH

docker image rm <image>

or

BASH

docker rmi <image>

List containers

BASH

docker container ls -a

or

BASH

docker ps -a

The -a option shows all containers (default shows just those running)

Remove containers

BASH

docker container rm <container>

or

BASH

docker rm <container>

Create and start a container based on a specific image

BASH

docker run [options] <image>

This command will be used later to create our CMS open data container.

The option -v for mounting a directory from the local computer to the container will also be used so that you can edit files on your normal editor and used them in the container:

BASH

docker -v <directory-on-your-local-computer>:<directory-in-the-container> <image>

Stop a running container

BASH

docker stop <container>

Start a container that was stopped

BASH

docker start -i <container>

Copy files in or out of a container

BASH

docker cp <container>:<path> <local path>
docker cp <local path> <container>:<path>

Key Points

  • For up-to-date details for installing Docker, the official documentation is the best bet.
  • Make sure you were able to download and run Docker’s hello-world example.
  • The concepts of image and container, plus the knowledge of certain Dockers commands, is all that is needed for the hands-on sessions.