Introducing the Docker command line

Overview

Teaching: 10 min
Exercises: 10 min
Questions
  • How do I interact with Docker?

Objectives
  • Explain how to check that Docker is installed and is ready to use.

  • Demonstrate some initial Docker command line interactions.

Docker command line

Start the Docker application that you installed in working through the setup instructions for this session. Note that this might not be necessary if your laptop is running Linux or if the installation added the Docker application to your startup process.

The Docker application will usually provide a way for you to log in using the application’s menu (macOS) or systray icon (Windows). This will require you to use your Docker Hub username and your password.

Determining your Docker Hub username

If you no longer recall your Docker Hub username, e.g., because you have been logging into the Docker Hub using your email address, you can find out what it is through the steps:

  • Open http://hub.docker.com/ in a web browser window
  • Sign-in using your email and password (don’t tell us what it is)
  • In the top-right of the screen you will see your username. Mine’s dme26.

Now open a shell (terminal) window, and run the following command to check that Docker is installed and the command line tools are working correctly. I have appended the output that I see on my Mac, but the specific version is unlikely to matter much: it certainly does not have to precisely match mine.

$ docker --version
Docker version 19.03.5, build 633a0ea

Ensure that your command line docker commands are able to reach the Docker Hub by running the following command:

$ docker login
Authenticating with existing credentials...
Login Succeeded

(I wasn’t prompted for authentication details, if you are, then you need to use your Docker Hub username and password.)

The Login Succeeded message means that your docker command line tool is ready to access the Docker Hub. We will return to discussion of the Docker Hub soon…

The above commands have not actually relied on the part of Docker that runs lightweight virtual machines being operational. Somewhat stretching a physical analogy, you can think of the above Docker commands having been instructions to the cranes on a hypothetical shipping dock, but we haven’t actually checked if the container ship we want to interact with is present yet. A command that checks that the virtual machine host is running is the Docker container list command, which we cover in a later episode.

Without explaining the details, output on a newly installed system would likely be:

$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

(The command docker info will achieve a similar end. but produces potentially daunting volumes of output.)

However, if you instead get a message similar to the following

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

then you need to check that you have started the Docker Desktop, Docker Engine, or however else you worked through the setup instructions.

Key Points

  • A toolbar icon indicates that Docker is ready to use.

  • You will typically interact with Docker using the command line.