CodeBlanks Logo Icon CodeBlanks

Installing Docker

Learn to install Docker Engine on Linux, macOS and Windows.

Installing Docker

There are two ways to install Docker:

  • Linux: Docker Engine is installed directly. The official script is the fastest way; then add your user to the docker group to stop typing sudo for every command.
  • Windows and macOS: Docker Desktop is installed; it runs a lightweight Linux virtual machine inside.
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER     # takes effect after logging out and in

Verifying the installation

Two checks are done after installing: that the client and daemon respond (docker version) and that a container can really run (docker run hello-world). A "permission denied ... docker.sock" error shows the user isn't in the docker group.

$ docker ps
permission denied while trying to connect to the Docker daemon socket
$ sudo usermod -aG docker $USER
$ newgrp docker      # activates the group in this session

Practice Installing on Linux

Write the command installing Docker with the official script, then the command adding the current user to the docker group.

Starter code

terminal
# buraya yaz

Sample solution

terminal
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER

Expected output

# Executing docker install script
+ sh -c 'docker version'
Client: Docker Engine - Community

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 How do Linux containers run on Windows and macOS?

  • They don't run
  • In a lightweight Linux virtual machine inside Docker Desktop Correct answer
  • Directly on the Windows kernel
  • In the browser

Explanation: A container shares the host kernel; a Linux container needs a Linux kernel.

2 Add the user to the docker group.

Question
sudo usermod -aG ____ $USER
Answer
sudo usermod -aG docker $USER

Explanation: Users in the docker group can access the daemon socket.

3 Match.

Term Meaning
get.docker.com Linux install script
Docker Desktop Windows/macOS installation
docker grubu No sudo needed
docker.sock Daemon socket

All lessons in Beginner