docker on ubuntu

Getting started with Docker on Ubuntu Linux

You want to get started with containers. But where to start? The first thing you want to do is to learn everything there is to know about Docker. This article will show you how to get started with Docker on Ubuntu Linux.

For this tutorial, you need a freshly installed Ubuntu server.

Why Ubuntu Linux and not Windows?


Let’s first go over why we are running Docker on Linux instead of Windows. Linux is generally the better choice because Docker was initially built around Linux kernel features, such as cgroups, namespaces, and union filesystems, meaning containers run natively without extra overhead. On Windows, Docker relies on a virtual machine (through WSL2 or Hyper-V) to provide a Linux kernel, which introduces additional complexity, increased resource usage, and slower performance. Linux also offers broader compatibility with container images and orchestration tools like Kubernetes, since most container workloads are developed and tested against Linux environments. In short, running Docker on Linux is faster, more efficient, and aligns better with how containers are designed to work.

Let’s get started with the installation of Docker on Ubuntu Linux

The first thing you need to do is to uninstall any conflicting packages. If you are using a freshly installed Ubuntu machine, the chances of any conflicting packages are very low. But run the command below anyway to be on the safe side.

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

Before installing Docker Engine on a new host for the first time, you must configure the Docker apt repository. Once the repository is set up, you can use it to install Docker and keep it up to date with future updates. Use the commands below.

# Add Docker's official GPG key:
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

# Add the repository to Apt sources:
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
sudo apt-get update

Now you are ready to install all the packages. Use the command below to begin the installation of Docker.

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

Manage Docker as a non-root user

By default, you need to preface the Docker command with sudo. To avoid that, you can add your user to the Docker group by using the command below. This is not recommended for use in a production environment.

sudo gpasswd -a $USER docker

Now Docker is installed. You can test your installation by typing the command’ docker’. If you want to try to run a container, you can try the Nginx container by using the command below.

docker run --name some-nginx -d -p 8080:80 some-content-nginx

Once it is up and running, type http://IP_OF_YOUR_MACHINE into your browser, and you will see that Nginx is running.

Find more container images and descriptions on how to use them on https://hub.docker.com/