This article is a walkthrough on installing Docker on Ubuntu Server 22.04.4 LTS
Install prerequisites
First we need to install some prerequisites:
sudo apt install ca-certificates curl gnupg lsb-release
Expected output:
Reading package lists... DoneBuilding dependency tree... DoneReading state information... Donelsb-release is already the newest version (11.1.0ubuntu4).lsb-release set to manually installed.ca-certificates is already the newest version (20230311ubuntu0.22.04.1).ca-certificates set to manually installed.curl is already the newest version (7.81.0-1ubuntu1.15).curl set to manually installed.gnupg is already the newest version (2.2.27-3ubuntu2.1).gnupg set to manually installed.0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
We now need to add in the Docker key into the keyring and add the Docker source:
sudo mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullsudo apt update
Expected output:
Hit:1 http://gb.archive.ubuntu.com/ubuntu jammy InReleaseGet:2 https://download.docker.com/linux/ubuntu jammy InRelease [48.8 kB]Hit:3 http://gb.archive.ubuntu.com/ubuntu jammy-updates InReleaseHit:4 http://gb.archive.ubuntu.com/ubuntu jammy-backports InReleaseGet:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [26.8 kB]Hit:6 http://security.ubuntu.com/ubuntu jammy-security InReleaseFetched 75.6 kB in 1s (144 kB/s)Reading package lists... DoneBuilding dependency tree... DoneReading state information... DoneAll packages are up to date.
Next is to install Docker itself:
sudo apt install docker-ce docker-ce-cli containerd.io
Reading package lists... DoneBuilding dependency tree... DoneReading state information... DoneThe following additional packages will be installed: docker-buildx-plugin docker-ce-rootless-extras docker-compose-plugin libltdl7 libslirp0 pigz slirp4netnsSuggested packages: aufs-tools cgroupfs-mount | cgroup-liteThe following NEW packages will be installed: containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libltdl7 libslirp0 pigz slirp4netns0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.Need to get 117 MB of archives.After this operation, 420 MB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://gb.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB]Get:2 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.6.28-1 [29.6 MB]Get:3 http://gb.archive.ubuntu.com/ubuntu jammy/main amd64 libltdl7 amd64 2.4.6-15build2 [39.6 kB]Get:4 http://gb.archive.ubuntu.com/ubuntu jammy/main amd64 libslirp0 amd64 4.6.1-1build1 [61.5 kB]Get:5 http://gb.archive.ubuntu.com/ubuntu jammy/universe amd64 slirp4netns amd64 1.0.1-2 [28.2 kB]Get:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.12.1-1~ubuntu.22.04~jammy [28.2 MB]Get:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:25.0.3-1~ubuntu.22.04~jammy [13.7 MB]Get:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:25.0.3-1~ubuntu.22.04~jammy [24.3 MB]Get:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:25.0.3-1~ubuntu.22.04~jammy [9,313 kB]Get:10 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.24.6-1~ubuntu.22.04~jammy [12.1 MB]Fetched 117 MB in 2s (53.3 MB/s)Selecting previously unselected package pigz.(Reading database ... 74546 files and directories currently installed.)Preparing to unpack .../0-pigz_2.6-1_amd64.deb ...Unpacking pigz (2.6-1) ...Selecting previously unselected package containerd.io.Preparing to unpack .../1-containerd.io_1.6.28-1_amd64.deb ...Unpacking containerd.io (1.6.28-1) ...Selecting previously unselected package docker-buildx-plugin.Preparing to unpack .../2-docker-buildx-plugin_0.12.1-1~ubuntu.22.04~jammy_amd64.deb ...Unpacking docker-buildx-plugin (0.12.1-1~ubuntu.22.04~jammy) ...Selecting previously unselected package docker-ce-cli.Preparing to unpack .../3-docker-ce-cli_5%3a25.0.3-1~ubuntu.22.04~jammy_amd64.deb ...Unpacking docker-ce-cli (5:25.0.3-1~ubuntu.22.04~jammy) ...Selecting previously unselected package docker-ce.Preparing to unpack .../4-docker-ce_5%3a25.0.3-1~ubuntu.22.04~jammy_amd64.deb ...Unpacking docker-ce (5:25.0.3-1~ubuntu.22.04~jammy) ...Selecting previously unselected package docker-ce-rootless-extras.Preparing to unpack .../5-docker-ce-rootless-extras_5%3a25.0.3-1~ubuntu.22.04~jammy_amd64.deb ...Unpacking docker-ce-rootless-extras (5:25.0.3-1~ubuntu.22.04~jammy) ...Selecting previously unselected package docker-compose-plugin.Preparing to unpack .../6-docker-compose-plugin_2.24.6-1~ubuntu.22.04~jammy_amd64.deb ...Unpacking docker-compose-plugin (2.24.6-1~ubuntu.22.04~jammy) ...Selecting previously unselected package libltdl7:amd64.Preparing to unpack .../7-libltdl7_2.4.6-15build2_amd64.deb ...Unpacking libltdl7:amd64 (2.4.6-15build2) ...Selecting previously unselected package libslirp0:amd64.Preparing to unpack .../8-libslirp0_4.6.1-1build1_amd64.deb ...Unpacking libslirp0:amd64 (4.6.1-1build1) ...Selecting previously unselected package slirp4netns.Preparing to unpack .../9-slirp4netns_1.0.1-2_amd64.deb ...Unpacking slirp4netns (1.0.1-2) ...Setting up docker-buildx-plugin (0.12.1-1~ubuntu.22.04~jammy) ...Setting up containerd.io (1.6.28-1) ...Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.Setting up docker-compose-plugin (2.24.6-1~ubuntu.22.04~jammy) ...Setting up libltdl7:amd64 (2.4.6-15build2) ...Setting up docker-ce-cli (5:25.0.3-1~ubuntu.22.04~jammy) ...Setting up libslirp0:amd64 (4.6.1-1build1) ...Setting up pigz (2.6-1) ...Setting up docker-ce-rootless-extras (5:25.0.3-1~ubuntu.22.04~jammy) ...Setting up slirp4netns (1.0.1-2) ...Setting up docker-ce (5:25.0.3-1~ubuntu.22.04~jammy) ...Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.Processing triggers for man-db (2.10.2-1) ...Processing triggers for libc-bin (2.35-0ubuntu3.6) ...Scanning processes...Scanning processor microcode...Scanning linux images...Running kernel seems to be up-to-date.The processor microcode seems to be up-to-date.No services need to be restarted.No containers need to be restarted.No user sessions are running outdated binaries.No VM guests are running outdated hypervisor (qemu) binaries on this host.
Almost done. We need to add your user in to the docker group so that we don’t have to run it with sudo all the time:
sudo usermod -aG docker $USER
And to ensure all is in place, we need to log out and back in. Once you have logged back in, you can test that Docker is set up correctly as your user. Do not use sudo at the start of the command:
docker run hello-world
Expected output:
Unable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldc1ec31eb5944: Pull completeDigest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21dStatus: Downloaded newer image for hello-world:latestHello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID: https://hub.docker.com/For more examples and ideas, visit: https://docs.docker.com/get-started/
And that is that, we have installed Docker!
Leave a Reply