Skip to content

Instantly share code, notes, and snippets.

@programmerShinobi
Last active September 18, 2024 11:03
Show Gist options
  • Save programmerShinobi/23c1577042276ca4d943ddf7598a17cb to your computer and use it in GitHub Desktop.
Save programmerShinobi/23c1577042276ca4d943ddf7598a17cb to your computer and use it in GitHub Desktop.
Install Docker Engine on Ubuntu

OS requirements

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:

  • Ubuntu Noble 24.04 (LTS)
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)

Docker Engine for Ubuntu is compatible with x86_64 (or amd64), armhf, arm64, s390x, and ppc64le (ppc64el) architectures.

Uninstall old versions

Before you can install Docker Engine, you need to uninstall any conflicting packages.

Distro maintainers provide unofficial distributions of Docker packages in APT. You must uninstall these packages before you can install the official version of Docker Engine.

The unofficial packages to uninstall are:

  • docker.io
  • docker-compose
  • docker-compose-v2
  • docker-doc
  • podman-docker

Moreover, Docker Engine depends on containerd and runc. Docker Engine bundles these dependencies as one bundle: containerd.io. If you have installed the containerd or runc previously, uninstall them to avoid conflicts with the versions bundled with Docker Engine.

Run the following command to uninstall all conflicting packages:

$ for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Installation methods

Install using the apt repository Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

  1. Set up Docker's apt repository.
    $ sudo apt-get update
    $ sudo apt-get install ca-certificates curl
    $ sudo install -m 0755 -d /etc/apt/keyrings
    $ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    $ sudo chmod a+r /etc/apt/keyrings/docker.asc
    $ echo \
        "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
        $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
        sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    $ sudo nano /etc/apt/sources.list.d/docker.list
      # replace line 1 (replace 'horus' to 'jammy' :
        deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu   jammy stable
  2. Update your existing list of packages again for the addition to be recognized.
    $ sudo apt update
  3. Make sure you are about to install from the Docker repo instead of the default Ubuntu repo.
    $ apt-cache policy docker-ce
    Output:
    docker-ce:
        Installed: 5:27.2.1-1~ubuntu.22.04~jammy
        Candidate: 5:27.2.1-1~ubuntu.22.04~jammy
        Version table:
        *** 5:27.2.1-1~ubuntu.22.04~jammy 500
                500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
                100 /var/lib/dpkg/status
            5:27.2.0-1~ubuntu.22.04~jammy 500
                500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
  4. Install the Docker packages.
    $ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  5. Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running.
    $ sudo systemctl status docker
    Output:
    ● docker.service - Docker Application Container Engine
         Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
         Active: active (running) since Wed 2024-09-18 17:26:05 WIB; 31min ago
    TriggeredBy: ● docker.socket
           Docs: https://docs.docker.com
       Main PID: 42386 (dockerd)
          Tasks: 14
         Memory: 25.8M
            CPU: 1.332s
         CGroup: /system.slice/docker.service
                 └─42386 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
  6. Verify that the Docker Engine installation is successful by running the hello-world image.
    $ sudo docker run hello-world

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment