Installation and Usage Guide for Docker on Ubuntu 20.04
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.
Prerequisites
- A system running Ubuntu 20.04
- A user account with sudo privileges
- Internet access
Step 1: Update System Packages
Before installing Docker, update the package repository to ensure you have the latest software versions:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
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
Step 3: Add Docker’s Official GPG Key
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
Step 4: Add the Docker Repository
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
Step 5: Install Docker
Update the package list and install Docker Engine:
sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io
Step 6: Verify Docker Installation
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
Step 7: Run Docker Without Sudo (Optional)
By default, Docker requires
sudoprivileges. To run it as a non-root user, add your user to the
dockergroup:
sudo usermod -aG docker $USER
Log out and log back in for the changes to take effect.
Step 8: Test Docker Installation
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.
Basic Docker Commands
Pull an Image
To download an image from Docker Hub:
docker pull ubuntu
List Installed Images
docker images
Run a Container
To start a container from an image:
docker run -it ubuntu bash
This command runs an Ubuntu container and opens an interactive shell.
List Running Containers
docker ps
To see all containers, including stopped ones:
docker ps -a
Stop a Container
To stop a running container:
docker stop <container_id>
Remove a Container
To remove a stopped container:
docker rm <container_id>
Remove an Image
To delete an image:
docker rmi <image_id>
Clean Up Unused Resources
Remove all stopped containers and unused images:
docker system prune -a
Conclusion
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.


