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 -y
Docker 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-common
To 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.gpg
Add 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/null
Update the package list and install Docker Engine:
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
Check if Docker is installed correctly by running:
docker --version
To ensure Docker is running:
sudo systemctl status docker
If it is not running, start it with:
sudo systemctl start docker
To enable Docker to start on boot:
sudo systemctl enable docker
By default, Docker requires sudo
privileges. To run it as a non-root user, add your user to the docker
group:
sudo usermod -aG docker $USER
Log 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-world
If the installation is successful, you should see a message confirming that Docker is running properly.
To download an image from Docker Hub:
docker pull ubuntu
docker images
To start a container from an image:
docker run -it ubuntu bash
This command runs an Ubuntu container and opens an interactive shell.
docker ps
To see all containers, including stopped ones:
docker ps -a
To 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 -a
Docker 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.