Install Docker CE on Ubuntu 24.04

Install Docker CE on Ubuntu 24.04

Docker is an open-source platform for developing, testing, and running applications. Docker provides a way to package and run an application in a container. A container is an isolated environment which contains everything needed for an application to run.

This tutorial explains how to install Docker Community Edition (CE) on Ubuntu 24.04.

Prepare environment

Update the package lists using the following command:

sudo apt update

Install package that allows to use a repository accessed via the HTTP:

sudo apt install -y apt-transport-https

Install Docker CE

Download GPG key and add to a specified directory:

wget -qO - https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Add the Docker CE repository:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -sc) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Install the Docker CE:

sudo apt update
sudo apt install -y docker-ce

By default, root and user with sudo privileges can use Docker. During installation, a group docker is created. So, if you want to allow using Docker for non-root users, you can add the user to the docker group.

Add current user to docker group:

sudo usermod -a -G docker $USER

To make changes to take effect, logout and login to your machine. After you're reconnected, check Docker version:

docker version

We can use the following command to determine if Docker service is running:

sudo service docker status

We can also stop, start and restart the Docker service:

sudo service docker stop
sudo service docker start
sudo service docker restart

Testing Docker CE

To test that Docker successfully installed, you can run the hello-world image.

docker run hello-world

The command downloads a test image, runs it in a container, prints a message, and exits.

Uninstall Docker CE

If you decided to completely remove Docker CE and related dependencies, run the following command:

sudo apt purge --autoremove -y docker-ce

When it finished, remove the docker group:

sudo groupdel docker

During installation, a network interface docker0 is installed. You can remove it with command:

sudo ip link delete docker0

Remove GPG key and repository:

sudo rm -rf /usr/share/keyrings/docker-archive-keyring.gpg
sudo rm -rf /etc/apt/sources.list.d/docker.list

You can also remove Docker configuration, images, containers, and other related directories:

sudo rm -rf /etc/docker
sudo rm -rf /var/lib/docker
sudo rm -rf /run/docker
sudo rm -rf /var/run/docker.sock
sudo rm -rf /var/lib/containerd
sudo rm -rf /opt/containerd

The 1 Comment Found

Leave a Comment

Cancel reply

Your email address will not be published.