How to Install Docker on Ubuntu

21 days ago

Using APT

  1. Update the package index

    sudo apt update
  2. Install required packages

    sudo apt-get install ca-certificates curl
  3. Make Docker’s official GPG key

    sudo install -m 0755 -d /etc/apt/keyrings
  4. Download Docker GPG key

    sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
  5. Set key permissions

    sudo chmod a+r /etc/apt/keyrings/docker.asc
  6. Set up the stable repository

    echo \
       "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
       $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
       sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  7. Update the package again

    sudo apt-get update
  8. Install the latest version

    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  9. Verify the installation

    sudo docker run hello-world

    This command downloads a test image and runs it in a container. If Docker is installed correctly, you will see a message saying "Hello from Docker!".

    Docker has been successfully installed and is ready to use!

From a Package

  1. Go to https://download.docker.com/linux/ubuntu/dists/
  2. Select your Ubuntu version in the list.
    • you can find out the Ubuntu version with this command
    lsb_release -c
  3. Go to pool/stable/ and select the applicable architecture (amd64, armhf, arm64, or s390x).
    • You can find out the architecture with this command
    dpkg --print-architecture
  4. Download the following deb files for the Docker Engine, CLI, containerd, and Docker Compose packages:
    • containerd.io_<version>_<arch>.deb
    • docker-ce_<version>_<arch>.deb
    • docker-ce-cli_<version>_<arch>.deb
    • docker-buildx-plugin_<version>_<arch>.deb
    • docker-compose-plugin_<version>_<arch>.deb
  5. Install the .deb packages. Update the paths in the following example to where you downloaded the Docker packages.
    sudo dpkg -i ./containerd.io_<version>_<arch>.deb \
      ./docker-ce_<version>_<arch>.deb \
      ./docker-ce-cli_<version>_<arch>.deb \
      ./docker-buildx-plugin_<version>_<arch>.deb \
      ./docker-compose-plugin_<version>_<arch>.deb
    The Docker daemon starts automatically.
  6. Verify the installation
    sudo service docker start
    sudo docker run hello-world
    This command downloads a test image and runs it in a container. If Docker is installed correctly, you will see a message saying "Hello from Docker!".
  7. Start Docker
    sudo systemctl start docker
    Docker has been successfully installed and is ready to use!