In this article we are going to cover How to Install Docker on Ubuntu 22.04 LTS
What is Docker ?
Docker is a software containerization platform that packages your application, all its libraries and configuration files in the form of a docker container where you can develop, ship and execute the applications.
In addition to it, Docker provides a robust client-server application architecture with a powerful server, REST API and command-line interface client. You can use the same infrastructure to run more containers and utilize fewer resources.
Docker can be installed on any operating system, it can be Mac, Windows, Linux and even cloud. It works only on 64 bit Linux installation and needs a Linux kernel of 3.10 and a higher version
Prerequisites
- Ubuntu 22.04 LTS Installed
- A user account with sudo privileges (to execute administrative commands).
Step #1:Update System Packages on Ubuntu 22.04 LTS
Update the APT package index on Ubuntu 22.04 LTS
ubuntu@Rushi-InfoTech:~$ sudo apt-get update
![](https://rushiinfotech.in/wp-content/uploads/2023/09/1-copy-16-1024x158.png)
OR
sudo apt update
Install required dependencies packages for docker
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
Step #2:Add GPG key for the official Docker repository in Ubuntu
Add the Docker GPG key to ensure the packages are valid:
ubuntu@Rushi-InfoTech:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step #3:Add the Docker repository to Ubuntu APT sources
Add the Docker repository to your APT sources:
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
If Ubuntu 22.04 LTS has a different codename, replace $(lsb_release -cs)
with the appropriate codename.
Update the package index again:
sudo apt update
Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
apt-cache policy docker-ce
Output:
docker-ce: Installed: (none) Candidate: 5:20.10.14~3-0~ubuntu-jammy Version table: 5:20.10.14~3-0~ubuntu-jammy 500 500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages 5:20.10.13~3-0~ubuntu-jammy 500 500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
Notice that docker-ce
is not installed, but the candidate for installation is from the Docker repository for Ubuntu 22.04 (jammy
).
Finally, install Docker:
Step #4:Install Docker on Ubuntu 22.04 LTS
Install docker on Ubuntu 22.04 LTS using below command
sudo apt install -y docker-ce docker-ce-cli containerd.io
To check Docker service status if it installed and running
sudo systemctl status docker
Output:
docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-04-01 21:30:25 UTC; 22s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 7854 (dockerd) Tasks: 7 Memory: 38.3M CPU: 340ms CGroup: /system.slice/docker.service └─7854 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
To start/stop/restart the Docker service and enable it to start on boot using sysemctl
sudo systemctl start docker sudo systemctl stop docker sudo systemctl restart docker sudo systemctl enable docker
Verify the installation of Docker on Ubuntu server.
ubuntu@Rushi-InfoTech:~$ docker --version
![](https://rushiinfotech.in/wp-content/uploads/2023/09/5-copy-12-1024x71.png)
Step #5:Running Docker commands without sudo
By default, the docker
command can only be run the root user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker
command without prefixing it with sudo
or without being in the docker group, you’ll get an output like this:
docker
Output:
If you want to avoid typing sudo
whenever you run the docker
command, add your username to the docker
group:
sudo usermod -aG docker ${USER}
To apply the new group membership, log out of the server and back in, or type the following:
su - ${USER}
You will be prompted to enter your user’s password to continue.
Confirm that your user is now added to the docker group by typing:
groups
output:
sudo docker
If you need to add a user to the docker
group that you’re not logged in as, declare that username explicitly using:
sudo usermod -aG docker username
The rest of this article assumes you are running the docker
command as a user in the docker group. If you choose not to, please prepend the commands with sudo
.
Step #6:Docker Command-Line
Before moving to Docker Images, Let’s see Docker commands. Before are docker command syntax.
ubuntu@Rushi-InfoTech:~$ docker [option] [command] [arguments]
- Run docker command to view all available sub commads.
ubuntu@Rushi-InfoTech:~$ docker
![](https://rushiinfotech.in/wp-content/uploads/2023/09/8-copy-5-1024x31.png)
Commands:
ubuntu@Rushi-InfoTech:~$ docker Usage: docker [OPTIONS] COMMAND Commands: attach Attach local standard input, output, and error streams to a running container commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server export Export a container's filesystem as a tar archive history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command. For more help on how to use Docker, head to https://docs.docker.com/go/guides/
Conclusion:
In this article we have covered How to Install Docker on Ubuntu 22.04 LTS
For Reference:
Please visit the official website of Docker.
Any queries pls contact us Rushi Infotech