Published on

7 min read

Installing Docker and Docker Compose

installing docker and docker compose banner image

Pick Your Operating System

You came here to ask, "how do I install Docker?" The answer can be straightforward if you're willing to accept my way, but the steps differ based on which operating system is utilized. To make things more complicated, there are a few ways to install Docker on your OS that are largely based on preference. Today I'm going to walk you through my preferred method. This isn't the only way, but I've found it to be the best way to get up and running with ease. For Ubuntu, we'll be setting up the Docker Engine. For Windows and macOS, we'll be using Docker Desktop.

Click on any of the links below to get started with installing Docker.

Installing Docker on Ubuntu

For Ubuntu, we're going to install Docker Engine and Docker Compose using the Docker and Compose repositories. This also happens to be the recommended approach by Docker.

Follow Along on YouTube

Set Up

  1. Delete any prior versions if you had installed them.
sudo apt-get remove docker docker-engine containerd runc
  1. Update your system and install the necessary dependencies.
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
  1. For security purposes, add Docker's official GPG key. Read more about that here.
curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. Set up the stable repository.
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

That's quite a few steps, but if you followed along exactly, you should be ready to install Docker!


  1. Install the latest version of Docker, along with its dependencies.
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli

If you are running a later version of Ubuntu than what Docker has official builds for, you may get the following error during this step.

Reading package lists... Done
Building dependency tree
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'docker-ce' has no installation candidate
E: Unable to locate package docker-ce-cli
E: Unable to locate package
E: Couldn't find any package by glob ''
E: Couldn't find any package by regex ''

But don't worry! We'll just need to go install the latest version that is available. This can be done with the following command INSTEAD of the one above.

sudo apt-get install -y
  1. Verify your install by running your first image.
sudo docker run hello-world
  1. Add your user as an admin to the Docker user group.
sudo usermod -aG docker $USER

Doing this last step means you no longer have to append sudo to run Docker commands!


Fed up with Docker on your Ubuntu box? Uninstall and remove the configuration files with the following commands.

sudo apt-get purge docker-ce docker-ce-cli
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

Installing Docker Compose on Ubuntu


You must have completed the installation of Docker Engine in the steps above before you can install Docker Compose. Assuming you've done so without any errors, let's continue on!

  1. Download the stable release of Docker compose.
sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Unlike the installation for Docker Engine where it automatically installs the latest version, Docker Compose has to have the version manually specified. At the time of writing, the latest version is 1.29.2. The latest version can be viewed at the Compose repository release page on GitHub. Feel free to substitute the version in the command above as needed.

installing docker and docker compose banner image
  1. Make the downloaded binary executable.
sudo chmod +x /usr/local/bin/docker-compose


To remove Docker Compose, utilize the following command (assuming you installed with curl as we did above).

sudo rm /usr/local/bin/docker-compose

Automated Installation Script for Linux (Ubuntu)

An automated installation script can be found here. The contents are pasted below.

echo "Starting docker community edition install..."
echo "Removing any old instances of docker and installing dependencies"
apt remove -y docker docker-engine containerd runc
apt update
apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
echo "Dowloading latest docker and adding official GPG key"
curl -fsSL | apt-key add -
echo "Pulling the latest repository"
add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
apt update
echo "Installing docker community edition"
apt install -y docker-ce docker-ce-cli
echo "Docker install completed, installing docker-compose"
echo "Dowloading docker-compose 1.29.2 - be sure to update to the latest stable"
curl -L "$(uname -s)-$(uname -m)" -o
echo "Setting binary permissions"
chmod +x /usr/local/bin/docker-compose
echo “Docker and docker-compose install complete”
# Run docker as non-root user on Ubuntu
sudo usermod -aG docker $USER

Installing Docker Desktop on macOS

Note that Docker Desktop comes pre-equipped with Docker Engine, Docker Compose, Kubernetes, and a few other goodies.


Intel or Apple Silicon

Depending on which chipset you have on your Mac, you'll need to install one of two versions of the Docker Desktop application. As this is a GUI application, there's not much needed other than navigating to the correct site and installing the .dmg file. Just drag and drop the Docker icon into your Applications directory.

installing docker and docker compose banner image

Docker for macOS with Intel

The official link for installing Docker Desktop for macOS with an Intel chipset can be found here.

Apple Silicon

We'll also need to take a few prior steps to get Docker Desktop running with Apple Silicon. Namely, you'll need to install Rosetta 2 with the following command.

softwareupdate --install-rosetta

Afterward, install Docker Desktop for macOS with an Apple Silicon chipset from here.


Within the Docker Desktop toolbar item, navigate to the menu > Troubleshoot > Uninstall. See the screenshot below.

installing docker and docker compose banner image

Installing Docker Desktop on Windows and WSL2

Note that Docker Desktop comes pre-equipped with Docker Engine, Docker Compose, Kubernetes, and a few other goodies. Firstly, you will need Docker Desktop even if you want Docker to only run on WSL. This is due to the sandboxed nature of WSL.



  1. First, you'll need to ensure that virtualization is enabled for your CPU in the BIOS. This differs amongst motherboard manufacturers and chipsets (namely Intel and AMD). A quick Google search will get you going though.
  2. The executable for Docker Desktop for Windows can be found here. It can also be found on Docker Hub. Click the installer, follow the prompts and wait for it to be downloaded.
installing docker and docker compose banner image
  1. During the process, be sure to allow the prompts for Enable Hyper-V Windows Features and the Install required Windows components for WSL 2.


You'll need to complete the steps for installing Docker Desktop on Windows before you can utilize WSL2. However, once you've completed it, feel free to come back to this section.

  1. Enable Use the WSL2 based engine in the Docker Desktop for Windows settings and Apply & Restart.
installing docker and docker compose banner image
  1. Be sure that WSL2 is set as your default and current distribution.

Check the current WSL mode.

wsl.exe -l -v

If not set to v2, upgrade your existing Linux.

wsl.exe --set-version (distro name) 2

Set v2 as the default version.

wsl.exe --set-default-version 2
  1. Navigate to WSL Integration and make sure Enable Integration with my default WSL distro is checked.
installing docker and docker compose banner image


Docker Desktop can be uninstalled from the Apps & features system settings. Just search for Docker Desktop and select Uninstall. Follow the prompts.

installing docker and docker compose banner image

More Questions or Need Help

Be sure to check out the official documentation for Docker Engine and Docker Desktop and if you have more questions, feel free to send a message with any of the media icons below!