Docker and Docker Compose Installation

Install Docker and Docker Compose Installation #

Install Docker Engine #

Uninstall old versions #

sudo apt remove docker docker-engine containerd runc

Set up the repository #

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt update
sudo apt install \
    ca-certificates \
    curl \
    gnupg \
  1. Add Docker’s official GPG key:
curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below.
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine #

sudo apt update
sudo apt install docker-ce docker-ce-cli

Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING>

Manage Docker as a non-root user #

  1. Create the docker group.
sudo groupadd docker
  1. Add your user to the docker group.
sudo usermod -aG docker $USER
  1. Log out and log back in so that your group membership is re-evaluated.

Configure Docker to start on boot #

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

To disable this behavior, use disable instead.

sudo systemctl disable docker.service
sudo systemctl disable containerd.service

Uninstall Docker Engine #

  1. Uninstall the Docker Engine, CLI, and Containerd packages:
sudo apt-get purge docker-ce docker-ce-cli
  1. Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

Install Docker Compose #

  1. Run this command to download the current stable release of Docker Compose:
sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose


sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  1. Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose

Note: If the command docker-compose fails after installation, check your path. You can also create a symbolic link to /usr/bin or any other directory in your path.

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  1. Test the installation
docker-compose --version
Edit Edit this page