How to install Docker on Ubuntu 24.04

In this article, we will learn how to install Docker on Ubuntu 24.04. Docker is a containerization platform that allows you to package and run applications in containers, which are lightweight, portable, and self-sufficient.
Before installing Docker, we need to add the Docker repository to our system. This can be done by running the following command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
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/nullAfter adding the Docker repository, we can install the Docker package by running the following command:
sudo apt update && apt-cache policy docker-ce && sudo apt install docker-ce
sudo systemctl status dockerAfter installing Docker, we need to add the current user to the Docker group to allow the user to run Docker commands without using sudo. This can be done by running the following command:
sudo usermod -aG docker ${USER} && su - ${USER}After installing Docker, we can install Docker Compose by running the following command:
sudo apt update && sudo apt install docker-ce-cli containerd.io docker-compose-plugin docker-compose
docker compose versionThere are several Docker commands that we can use to manage and run our containers. Here are some of the most Docker commands that we can use:
docker ps -aImportant
Change container_name with actual container name
docker exec -it container_name /bin/bashdocker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)sudo ls /var/lib/docker/volumesImportant
Change container_name with actual container name
docker logs -f container_nameImportant
Change container_name with actual container name
docker inspect container_namedocker compose up -d
docker compose down