Install Docker on Ubuntu Server

Install Docker on Ubuntu Server

This article will cover the step-by-step process of installing Docker on an Ubuntu Server.

Step 1. Update the apt package index.

sudo apt update

apt_update.png

Step 2. Install packages that allow us to use the repository over HTTPS.

 sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Step 3. Adding the official Docker GPG keys

sudo mkdir -p /etc/apt/keyrings

mkdir_keyrings_directory.png

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Step 4. Adding the Docker repository

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

added_docker_repository.png

Step 5. Update the apt package index once more, so we have the Docker packages added to the package index.

sudo apt update

apt_update.png

Step 6. Install Docker and its components

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin uidmap

install_docker_with_dependencies.png

Press Y to continue

Step 7. Start Docker.

The command below will start Docker.

sudo systemctl start docker

sudo_systemctl_start_docker.png

You can also enable Docker to run at startup. It will be useful if you are using it in production.

sudo systemctl enable docker

sudo_systemctl_enable_docker.png

Now that we have Docker installed, we can run the hello-world container.

sudo docker run hello-world

docker_run_hello_world.jpg

If the above command runs successfully, we can proceed further and set up Docker to execute rootlessly. It means we don't need to run sudo before the docker command.

dockerd-rootless-setuptool.sh install

docker_rootless_setup.jpg

We can now run any docker container rootless, so to test this, let's rerun the hello-world container.

docker run hello-world

docker_run_hello_world_rootless.jpg

We have successfully got Docker up and running.

Leave a comment and share this article if you found it helpful.

I'm Feeling Lucky
Darryl Dias

Written by Darryl Dias

The AI guy and founder of Caprycon, building AI-powered tools, exploring emerging technologies, and sharing insights from the world of artificial intelligence