Installing Docker and Docker Compose on Ubuntu
This guide will help you install Docker and Docker Compose on an Ubuntu system.
Prerequisites
- A system running Ubuntu (preferably 20.04 LTS or later)
- A user account with
sudoprivileges
Installing Docker
-
Update the package index:
sudo apt update -
Install required packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -
Add Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -
Set up the Docker repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -
Update the package index again:
sudo apt update -
Install Docker CE:
sudo apt install docker-ce -
Check the Docker service status:
sudo systemctl status docker -
Add your user to the
dockergroup to run Docker commands withoutsudo:sudo usermod -aG docker $USER -
Log out and log back in to apply the group changes.
Installing Docker Compose
-
Download Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose -
Apply executable permissions to the Docker Compose binary:
sudo chmod +x /usr/local/bin/docker-compose -
Verify the installation:
docker-compose --version
Verifying Docker and Docker Compose Installation
-
Run a simple Docker container:
docker run hello-worldThis command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message.
-
Check Docker Compose version:
docker-compose --versionThis command outputs the version of Docker Compose installed.
Congratulations! You have successfully installed Docker and Docker Compose on your Ubuntu system.