Introduction
In the realm of modern software development and deployment, presently Docker has emerged as a game-changer. Specifically Docker allows you to package applications and their dependencies into isolated containers, providing a consistent environment that can be easily replicated across different systems. This guide aims in detail to provide you with a comprehensive walkthrough on how to install and use Docker CE on Ubuntu 22.04. By the end of this article, finally you’ll have the skills to streamline your development processes and manage applications efficiently using Docker.
Table of Contents
Why Docker CE on Ubuntu 22.04?
Generally Docker CE revolutionizes the way we deploy and manage applications. By using containers, further you can bundle your apps with all they need, ensuring they run consistently and reliably no matter where they’re deployed.
Key Features of Docker
Key features of Docker include:
- Containerization: Basically Docker allows you to create containers that encapsulate the application code, runtime, libraries, and dependencies, providing a consistent and isolated environment for running the application.
- Portability: Docker containers can run on any system that supports Docker, regardless of the underlying infrastructure. This portability ensures that the application behaves the same way across different environments indeed.
- Resource Efficiency: Docker containers share the host system’s kernel, making them more lightweight than traditional virtual machines. Certainly this results in better resource utilization and faster startup times.
- Versioning and Reproducibility: Docker images are versioned, making it easy to roll back to a previous version if needed as well as previous.. It also ensures that the application’s behavior is reproducible across different environments.
- Scalability: Docker makes it easy to scale applications by creating multiple instances of containers and also distributing the load among them.
- Continuous Integration and Deployment (CI/CD): Another key point Docker plays a crucial role in modern software development workflows, as it facilitates continuous integration and deployment processes by providing a consistent environment for testing and production.
Prerequisites to Install Docker
Before we dive into the steps for installing Docker CE on Ubuntu 22.04, ensure that you’ve got the following requirements ready:
- Ubuntu 22.04: Firstly make sure you have a clean installation of Ubuntu Server, you can deploy this on a physical machine or a virtual environment like VMware or VirtualBox. To set this up, use following guide :
- A stable internet connection to download packages indeed.
- Of course basic familiarity with command-line operations.
Install Docker CE on Ubuntu 22.04
In this tutorial, I’ll walk you through the steps to install Docker on Ubuntu 22.04 and give you a complete rundown of the things you need before you start your adventure with containers and images.
Step 1: System Update
Firstly begin by ensuring your system is up to date. Open a terminal and execute the following commands:
samm@docker:~$ sudo apt-get update
samm@docker:~$ sudo apt-get upgrade
Of course this will update your package lists and upgrade installed packages to their latest versions. Once your package lists are updated, let’s proceed to the next step.
Step 2: Install Required Packages
Following the update of our system packages, the inclusion of several crucial packages necessary for Docker installation is imperative. To do that, we’ll use the following apt install command with sudo privileges. The command allows Ubuntu to securely connect to external repositories to retrieve in order to the packages we need.
samm@docker:~$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
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.13).
curl set to manually installed.
software-properties-common is already the newest version (0.99.22.7).
software-properties-common set to manually installed.
The following NEW packages will be installed:
apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,510 B of archives.
After this operation, 169 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://id.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 apt-transport-https all 2.4.9 [1,510 B]
Fetched 1,510 B in 0s (6,706 B/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 74097 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.4.9_all.deb ...
Unpacking apt-transport-https (2.4.9) ...
Setting up apt-transport-https (2.4.9) ...
Scanning processes...
Scanning candidates...
Scanning linux images...
Basically Docker CE relies on a few essential dependencies that must be installed. But don’t worry this is a straightforward process, and we’ll guide you through it.
To install Docker from the official source, then you’ll need to add Docker’s GPG (GNU Privacy Guard) key to your system. This step is important because it helps guarantee secure communication with the Docker repository.
After that you can use the curl command below to add Docker’s GPG key:
samm@docker:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 3: Install Docker on Ubuntu 22.04
Now that we’ve got the prerequisites in place, let’s move on to the installation of Docker. We’ll be installing Docker Community Edition (Docker CE), which is both open source and freely available for download and use. Let’s use the following command to add the Docker repository to APT source packages:
samm@docker:~$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Once more, update your existing list of packages to ensure that the addition is duly recognized:
samm@docker:~$ sudo apt update
Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB]
Hit:2 http://id.archive.ubuntu.com/ubuntu jammy InRelease
Get:3 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [21.2 kB]
Hit:4 http://id.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:5 http://id.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:6 http://id.archive.ubuntu.com/ubuntu jammy-security InRelease
Fetched 70.1 kB in 1s (114 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
samm@docker:~$ apt-cache policy docker-c
You’ll see output like this, although the version number for Docker may be different:
docker-ce:
Installed: (none)
Candidate: 5:24.0.5-1~ubuntu.22.04~jammy
Version table:
5:24.0.5-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:24.0.4-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:24.0.3-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:24.0.2-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:24.0.1-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:24.0.0-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:23.0.6-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:23.0.5-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:23.0.4-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:23.0.3-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:23.0.2-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:23.0.1-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:23.0.0-1~ubuntu.22.04~jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
.....
Observe that docker-ce is not currently installed, but the candidate for installation originates from the Docker repository for Ubuntu 22.04 (jammy).
Finally, install Docker:
samm@docker:~$ sudo apt install docker-ce
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
containerd.io docker-buildx-plugin docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libltdl7 libslirp0 pigz slirp4netns
Suggested packages:
aufs-tools cgroupfs-mount | cgroup-lite
The 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 slirp4netns
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 114 MB of archives.
After this operation, 415 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Eventually you should now have Docker installed, with the daemon started and the process enabled to initiate on boot. Verify that Docker is running by checking its status and use following command:
samm@docker:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-07-31 03:18:23 WIB; 1min 40s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 830 (dockerd)
Tasks: 10
Memory: 100.0M
CPU: 557ms
CGroup: /system.slice/docker.service
└─830 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Jul 31 03:18:22 docker dockerd[830]: time="2023-07-31T03:18:22.532154384+07:00" level=info msg="Starting up"
Jul 31 03:18:22 docker dockerd[830]: time="2023-07-31T03:18:22.542081903+07:00" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv.conf"
Jul 31 03:18:22 docker dockerd[830]: time="2023-07-31T03:18:22.891713957+07:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Jul 31 03:18:22 docker dockerd[830]: time="2023-07-31T03:18:22.898680911+07:00" level=info msg="Loading containers: start."
Jul 31 03:18:23 docker dockerd[830]: time="2023-07-31T03:18:23.392364491+07:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a pr>
Jul 31 03:18:23 docker dockerd[830]: time="2023-07-31T03:18:23.454899588+07:00" level=info msg="Loading containers: done."
Jul 31 03:18:23 docker dockerd[830]: time="2023-07-31T03:18:23.711671124+07:00" level=info msg="Docker daemon" commit=a61e2b4 graphdriver=overlay2 version=24.0.5
Jul 31 03:18:23 docker dockerd[830]: time="2023-07-31T03:18:23.712631632+07:00" level=info msg="Daemon has completed initialization"
Jul 31 03:18:23 docker dockerd[830]: time="2023-07-31T03:18:23.787896795+07:00" level=info msg="API listen on /run/docker.sock"
Jul 31 03:18:23 docker systemd[1]: Started Docker Application Container Engine.
Installing Docker now gives you not just the Docker service (daemon) but also the docker command line utility, or the Docker client.
Step 4: Executing the Docker Command Without Sudo
By default, the docker command can only be run the root user or by a user in the docker group, which is automatically created during process of install Docker. “If you try to run the ‘docker’ command without using ‘sudo’ or without being part of the ‘docker‘ group, you’ll receive following an output similar to this:”
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
Then the next step in the installation of Docker on Ubuntu Server 22.04 is to make Docker run without needing ‘sudo.’ By default, users have to prepend ‘sudo’ to every Docker command. Hence, we add our current user to its group to solve this.
[sudo usermod -aG docker $username]
samm@docker:~$ sudo usermod -aG docker samm
samm@docker:~$ sudo chmod 666 /var/run/docker.sock
Afterwards reload shell session
samm@docker:~$ newgrp docker
Step 5: Check Docker Version
Verify that the Docker command is working fine by querying the version of you Containerization software using following command:
samm@docker:~$ docker version
Client: Docker Engine - Community
Version: 24.0.5
API version: 1.43
Go version: go1.20.6
Git commit: ced0996
Built: Fri Jul 21 20:35:18 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.5
API version: 1.43 (minimum version 1.12)
Go version: go1.20.6
Git commit: a61e2b4
Built: Fri Jul 21 20:35:18 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.21
GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc:
Version: 1.1.7
GitCommit: v1.1.7-0-g860f061
docker-init:
Version: 0.19.0
GitCommit: de40ad0
You can also check the docker info using following command:
samm@docker:~$ docker info
Client: Docker Engine - Community
Version: 24.0.5
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.11.2
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.20.2
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 24.0.5
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc version: v1.1.7-0-g860f061
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 5.15.0-78-generic
Operating System: Ubuntu 22.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.82GiB
Name: docker
ID: b4b10b95-8c68-406d-bf1b-2fe3e721df49
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Step 6: Testing Docker with a Test Image
Let’s move on to downloading a Docker test image, which is essentially a read-only file, and then running it within a container. By default, Docker fetches these images from the Docker Hub, and this applies to the ‘hello-world’ image used in our test using following command:
samm@docker:~$ docker run hello-world
Docker was initially unable to find the hello-world image locally, so it downloaded the image from Docker Hub, which is the default repository. Once the image downloaded, Docker created a container from the image and the application within the container executed, displaying the message.
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:926fac19d22aa2d60f1a276b66a20eb765fbeea2db5dbdaafeb456ad8ce81598
Status: Downloaded newer image for hello-world:latest
Hello 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 bash
Share 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/
Similarly you can search for images available on Docker Hub by using the docker command with the search subcommand. For example, to search for the Ubuntu image, type:
samm@docker:~$ docker search ubuntu
The script will crawl Docker Hub and return a listing of all images whose name matches the search string in detail. In this case, the output will be similar to this:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 16222 [OK]
websphere-liberty WebSphere Liberty multi-architecture images … 296 [OK]
open-liberty Open Liberty multi-architecture images based… 61 [OK]
neurodebian NeuroDebian provides neuroscience research s… 103 [OK]
ubuntu-debootstrap DEPRECATED; use "ubuntu" instead 52 [OK]
ubuntu-upstart DEPRECATED, as is Upstart (find other proces… 115 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 97
ubuntu/cortex Cortex provides storage for Prometheus. Long… 4
ubuntu/squid Squid is a caching proxy for the Web. Long-t… 63
ubuntu/apache2 Apache, a secure & extensible open-source HT… 59
ubuntu/kafka Apache Kafka, a distributed event streaming … 32
ubuntu/mysql MySQL open source fast, stable, multi-thread… 51
ubuntu/bind9 BIND 9 is a very flexible, full-featured DNS… 57
ubuntu/prometheus Prometheus is a systems and service monitori… 44
ubuntu/postgres PostgreSQL is an open source object-relation… 31
ubuntu/redis Redis, an open source key-value store. Long-… 19
ubuntu/zookeeper ZooKeeper maintains configuration informatio… 9
ubuntu/grafana Grafana, a feature rich metrics dashboard & … 9
ubuntu/memcached Memcached, in-memory keyvalue store for smal… 5
ubuntu/dotnet-deps Chiselled Ubuntu for self-contained .NET & A… 9
ubuntu/prometheus-alertmanager Alertmanager handles client alerts from Prom… 9
ubuntu/dotnet-aspnet Chiselled Ubuntu runtime image for ASP.NET a… 10
ubuntu/dotnet-runtime Chiselled Ubuntu runtime image for .NET apps… 9
ubuntu/cassandra Cassandra, an open source NoSQL distributed … 2
ubuntu/telegraf Telegraf collects, processes, aggregates & w… 4
As shown above in the OFFICIAL column, OK indicates an image built and supported by the company behind the project. Once you’ve identified the image that you would like to use, you can download it to your server using the pull subcommand.
Execute the following command to download the official ubuntu image to your server:
samm@docker:~$ docker pull ubuntu
You’ll see the following output:
Using default tag: latest
latest: Pulling from library/ubuntu
3153aa388d02: Pull complete
Digest: sha256:0bced47fffa3361afa981854fcabcd4577cd43cebbb808cea2b1f33a3dd7f508
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
Step 7: Test Run Docker
Once you have downloaded an image, you can proceed to run a container using the downloaded image through the run subcommand. As demonstrated in the hello-world example, when you execute docker with the run subcommand and the image has not been downloaded, the Docker client will initiate the image download and then proceed to run a container using it.
Type the following command to view the images that have been downloaded to your server:
samm@docker:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 5a81c4b8502e 4 weeks ago 77.8MB
hello-world latest 9c7a54a9a43c 2 months ago 13.3kB
After that let’s run a container using the latest image of Ubuntu. The combination of the -i and -t switches gives you interactive shell access into the container by run the following command:
samm@docker:~$ docker run -it ubuntu
Shortly you’ll notice a change in your command prompt, indicating that you’re now operating inside the container. It should look something like this:
root@f48f24fbee15:/#
Note the container id in the command prompt. i.e. it is f48f24fbee15. You’ll need that container ID later to identify the container when you want to remove it.
Then you can run any command inside the container. For example, let’s update the package database inside the container. You don’t need to prefix any command with sudo, because you’re operating inside the container as the root user:
root@f48f24fbee15:/# apt update
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:3 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [802 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
Get:7 http://security.ubuntu.com/ubuntu jammy-security/multiverse amd64 Packages [44.0 kB]
Get:8 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 Packages [969 kB]
Get:9 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [848 kB]
Get:10 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Get:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
Get:12 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
Get:13 http://archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 Packages [49.8 kB]
Get:14 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 Packages [863 kB]
Get:15 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1230 kB]
Get:16 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [1087 kB]
Get:17 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [49.4 kB]
Get:18 http://archive.ubuntu.com/ubuntu jammy-backports/universe amd64 Packages [25.6 kB]
Fetched 26.3 MB in 7s (3636 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
Then install any application in it. Let’s install Node.js by using following command:
root@f48f24fbee15:/# apt install nodejs
This command, meanwhile, installs Node.js within the container, directly from the official Ubuntu repository. Once the installation is complete, verify the presence of Node.js:
root@f48f24fbee15:/# node -v
v12.22.9
Henceforth ny changes you make inside the container only apply to that container.
Afterward to exit the container, type exit at the prompt.
Once the container is created, it automatically exits or stops. However, you can still inspect stopped containers, as demonstrated below.
samm@docker:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f48f24fbee15 ubuntu "/bin/bash" 8 minutes ago Exited (0) 2 seconds ago inspiring_curran
0002734f99a5 hello-world "/hello" 17 minutes ago Exited (0) 17 minutes ago awesome_dubinsky
Docker Compose and Multi-Container Applications
When dealing with intricate applications that need multiple containers to collaborate smoothly, turn to Docker Compose. In this article, we’ll walk you through the fundamentals, so you can get started with ease: How To Install and Use Docker Compose
Conclusion
Finally Congratulations! You’ve successfully installed Docker CE on your Ubuntu 22.04 system. Moreover Docker’s containerization technology empowers you to build, ship, and run applications with incredible ease and consistency. Besides that you now possess the skills to create, manage, and deploy containers, making your development workflows more efficient and streamlined. Even more the world of containerization is at your fingertips – dive in and unlock its potential! Whether you’re a developer, system administrator, or IT professional, Docker will undoubtedly revolutionize your approach to software deployment.
Also Read Our Other Guides :
- How To Install and Configure Elasticsearch on Ubuntu Server 22.04
- How To Install Docker CE on Rocky Linux 9
- How To Install Docker CE on Centos 7
- How To Install and Use Docker Compose on Centos 7
- Install and Configure Docker Swarm Mode on Centos 7
As I have shown, now you have learned how to install Docker CE on Ubuntu 22.04.