Docker is an open-source platform that simplifies the process of developing, shipping, and running applications inside containers. This guide will cover the installation of Docker on Ubuntu 20.04 and provide an overview of its basic usage.
Before installing Docker, update the package repository to ensure you have the latest software versions:
sudo apt update && sudo apt upgrade -yDocker requires certain dependencies to be installed. Run the following command to install them:
sudo apt install -y apt-transport-https ca-certificates curl software-properties-commonTo verify the authenticity of the Docker package, add its GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgAdd the official Docker repository to your system sources:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg]
https://download.docker.com/linux/ubuntu focal stable" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullUpdate the package list and install Docker Engine:
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.ioCheck if Docker is installed correctly by running:
docker --versionTo ensure Docker is running:
sudo systemctl status dockerIf it is not running, start it with:
sudo systemctl start dockerTo enable Docker to start on boot:
sudo systemctl enable dockerBy default, Docker requires sudo privileges. To run it as a non-root user, add your user to the docker group:
sudo usermod -aG docker $USERLog out and log back in for the changes to take effect.
Run a test container to verify that Docker is working correctly:
docker run hello-worldIf the installation is successful, you should see a message confirming that Docker is running properly.
To download an image from Docker Hub:
docker pull ubuntudocker imagesTo start a container from an image:
docker run -it ubuntu bashThis command runs an Ubuntu container and opens an interactive shell.
docker psTo see all containers, including stopped ones:
docker ps -aTo stop a running container:
docker stop <container_id>To remove a stopped container:
docker rm <container_id>To delete an image:
docker rmi <image_id>Remove all stopped containers and unused images:
docker system prune -aDocker is a powerful tool that simplifies application deployment and management. This guide covered the installation process and basic commands to help you get started with Docker on Ubuntu 20.04.