Docker is a set of platform-as-a-service products that uses OS-level virtualization to deliver software in packages called containers. Containers are usually isolated from one another and bundled with their own software libraries and configuration files, they can communicate with each other through well-defined channels.
Docker makes it possible to get more apps running on the same old servers and also makes it easy to package and ship programs. In this tutorial am going to show you how you can install Docker-CE on Ubuntu 20.04.
- How to install and use Docker-ce on Fedora 35
- How to install Docker on Arch Linux
- How to install Docker-ce on Ubuntu 21.10
- How to install and configure Docker-CE on Ubuntu 20.04
- Make sure you have a user with sudo privileges
- Have Ubuntu 22.04 server up and running
- Have basic knowledge about running commands on a shell
Install Docker-ce on Ubuntu 22.04
1. Update system repositories
Let’s begin by updating our system repositories to make them up to date.
sudo apt update && apt upgrade -y
When both updates and upgrades are complete, we can go ahead and uninstall old Docker versions.
2. Uninstall old versions of Docker
Old versions of Docker were called docker, docker.io or docker-engine. Uninstall them before installing the new one.
sudo apt-get remove docker docker-engine docker.io containerd runc
If they were not installed then you will see an output like this:
# output Reading package lists... Done Building dependency tree... Done Reading state information... Done Package 'docker-engine' is not installed, so not removed Package 'containerd' is not installed, so not removed Package 'runc' is not installed, so not removed Package 'docker' is not installed, so not removed Package 'docker.io' is not installed, so not removed The following packages were automatically installed and are no longer required: docker-ce-rootless-extras docker-scan-plugin libslirp0 pigz slirp4netns Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
3. Installing Docker on Ubuntu 22.04
There are three methods we can install Docker,
- Install using the DEB repository
- Install from the packages
- Install using a convenient script
Install using .deb Repository
We are installing docker here for the first time, so we need to set up the Docker repository in our system.
To set up the repository first install required dependencies such as, ca-certificates, curl, GnuPG and lsb-release.
sudo apt install ca-certificates curl gnupg lsb-release
The output will be as follows:
Reading package lists... Done Building dependency tree... Done Reading state information... Done ca-certificates is already the newest version (20211016). gnupg is already the newest version (2.2.27-3ubuntu2). gnupg set to manually installed. lsb-release is already the newest version (11.1.0ubuntu4). lsb-release set to manually installed. curl is already the newest version (7.81.0-1ubuntu1.1). The following packages were automatically installed and are no longer required: docker-ce-rootless-extras docker-scan-plugin libslirp0 pigz slirp4netns Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Then the next step is to install GPG key to sign the docker images being installed.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
The next step is to set up a stable, nightly, or test repository depending on what you want to install.
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
Lastly, let’s install the Docker engine. To check the available versions we can use the apt-cache madison docker-ce command.
$ sudo apt-cache madison docker-ce docker-ce | 5:20.10.15~3-0~ubuntu-jammy | https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages docker-ce | 5:20.10.14~3-0~ubuntu-jammy | https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages docker-ce | 5:20.10.13~3-0~ubuntu-jammy | https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
Before we can install the Docker engine let’s update our repositories one more time.
$ sudo apt update $ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
4. Enable Docker
We need to enable docker-ce to start on reboot, in order to avoid starting every time you boot your machine.
sudo systemctl enable docker
5. Start Docker service
You are supposed to start the docker service to run containerd environment. To start, use the following command.
sudo systemctl start docker
Lastly, we can check the status of docker to see if it is running.
6. Check the status of Docker
Check if Docker is running with the following command on your terminal.
$ sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset> Active: active (running) since Mon 2022-05-09 09:45:15 EAT; 8min ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 9636 (dockerd) Tasks: 10 Memory: 30.5M CPU: 477ms CGroup: /system.slice/docker.service └─9636 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont> May 09 09:45:14 zx-pc dockerd: time="2022-05-09T09:45:14.783146457+03:00"> May 09 09:45:14 zx-pc dockerd: time="2022-05-09T09:45:14.783171530+03:00">
If you got status active, then your docker service is running as expected, if not probably you haven’t started the service.
7. Test Docker
Let’s test our docker to see if it is running. Test using hello-world container. This will pull hello-world image from docker hub
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67 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/
We can try to install ubuntu like this docker run -it ubuntu bash
$ sudo docker run -it ubuntu bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 125a6e411906: Pull complete Digest: sha256:26c68657ccce2cb0a31b330cb0be2b5e108d467f641c62e13ab40cbec258c68d Status: Downloaded newer image for ubuntu:latest [email protected]:/#
You now have running ubuntu inside a docker container.
Install Docker using a convenient script
Using this method is not recommended for the production environment. Use it only when doing some tests.
To download the script run the following:
curl -fsSL https://get.docker.com -o get-docker.sh
Then execute the script with this command:
sudo sh get-docker.sh
Install Docker from the Package
To install Docker from the package, go to docker distros page and chose Ubuntu distribution, then choose if you want stable, nightly or test version.
Download the package
Run the installation using the following command:
sudo dpkg -i /path/to/package.deb
Whenever you want to uninstall docker from your machine, use the following command to completely remove the installation.
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
Then you need to delete all the images, volumes, and containers with these commands
$ sudo rm -rf /var/lib/docker $ sudo rm -rf /var/lib/containerd
From here you can see our Docker is running as expected, Learn other docker commands to be well conversant with docker. Docker Documentation has a tone of information.