Installing Docker and Docker-Compose on Ubuntu 20.04
This is my notes for installing Docker and Docker-Compose on our Ubuntu machines in our lab. Docker is used to deploy and manage containers. Docker-Compose makes it easier to create configurations for the containers.
Prerequisites
You will need to have sudo or root privileges to run commands and install packages.
Step 1: Updating System Packages
The first step is to update the system packages to their latest versions. Open a terminal and run the following commands:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
These commands update the package lists, install necessary dependencies, and enable the system to securely download packages over HTTPS.
Step 2: Installing Docker
To install Docker, we need to add the Docker repository and install the Docker Community Edition (CE) package. Follow the steps below:
- Add the Docker repository GPG key to ensure the authenticity of the packages:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Add the Docker repository to the APT sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
- Update the package lists again:
sudo apt update
- Install Docker CE:
sudo apt install docker-ce -y
Now, Docker should be installed on your Ubuntu 20.04 system. To verify the installation, you can check the status of the Docker service:
sudo systemctl status docker
You should see a status message indicating that the Docker service is active and running.
- (Optional) Allowing Docker Commands Without sudo
By default, Docker requires sudo privileges to run commands. If you want to run Docker commands without using sudo, you can add your user to the “docker” group:
sudo usermod -aG docker ${USER}
After executing this command, you will need to log out and log back in for the changes to take effect. Once you log back in, you will be able to use Docker commands without sudo.
Step 3: Installing Docker-Compose
Docker-Compose is not included in the official Ubuntu repositories. However, it can be easily installed using the following steps:
- Download the Docker-Compose binary (Check GitHub for the latest version and update the URL to reflect.):
sudo curl -L "https://github.com/docker/compose/releases/download/2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
- Verify the installation by checking the Docker-Compose version:
docker-compose --version
You should see the version number of Docker-Compose displayed in the terminal, indicating a successful installation.
Other Thoughts
I do NOT recommend using this, but this is a quick and dirty way to “script” out the install. The &&
ensures that each command is only run is the previous command was successful. I run this as my user, which has root privileges.
sudo apt update && sudo apt install apt-transport-https ca-certificates curl software-properties-common -y && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" && sudo apt update && sudo apt install docker-ce -y && sudo systemctl status docker && sudo usermod -aG docker ${USER} && sudo curl -L "https://github.com/docker/compose/releases/download/2.18.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && docker-compose --version