How to Install Docker on Linux and Run Your First Container

Docker is a platform for packaging and running applications in isolated units called containers. Each container bundles an application together with its libraries and dependencies, sharing the host’s Linux kernel instead of a full separate OS.

In practice, containers are much lighter than traditional virtual machines, yet they allow you to deploy services (websites, databases, media servers, etc.) on any Linux host. For example, a Linux server can run a personal website, a media server, and cloud storage in Docker containers.

How to Install Docker on Linux and Run Your First Container

This guide (using Ubuntu 24.04 LTS) walks through installing Docker on a Linux server or VM and starting your first container. These steps also work on similar distros like Debian 12/13, Ubuntu 22.04, etc.

Install Docker on Ubuntu 24.04 LTS

First, update your package index and install required tools (for HTTPS repositories):

sudo apt update
sudo apt install -y ca-certificates curl gnupg

Next, add Docker’s official APT repository. This lets you install the latest Docker Engine. Run:

# Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

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

Note: These steps follow Docker’s official instructions. Find instructions for your distro here

Now install Docker Engine and related tools:

sudo apt update && sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

This installs Docker Engine: the command-line interface, the container runtime, and the Docker Compose plugin. The Docker service should start automatically. You can check its status with sudo systemctl status docker. If it isn’t running, start it with sudo systemctl start docker.

Optional: To run Docker without typing sudo, add your user to the docker group:

sudo usermod -aG docker $USER

Then log out and back in (or reboot) so the group change takes effect.

Run Your First Docker Container

Run Your First Docker Container - hello world

With Docker installed, let’s run a test container. Docker uses images (templates) to create containers. Docker Hub (the online image registry) has many official images. A good first test is the hello-world image. In your terminal, run:

docker run hello-world

(The sudo is not needed if your user is in the docker group.) Docker will download the hello-world image and run it. You should see a message like “Hello from Docker!” confirming the install.

As the Docker docs explain, hello-world is a test image that prints a confirmation and then exits. For example, after running the command, you’ll see output similar to:

Hello from Docker!
This message shows that your installation appears to be working correctly.
...

This means Docker successfully ran the container and printed its message.

You can now inspect containers and images:

  • docker ps shows running containers (there will be none after hello-world exited).
  • docker ps -a shows all containers (including stopped ones). You should see the hello-world container in the list.
  • docker images lists downloaded images (you’ll see hello-world there).

As another quick test, try running an interactive Ubuntu shell container:

docker run -it ubuntu:24.04 bash

This command downloads the Ubuntu 24.04 image (if not already present) and runs bash inside a new container. You’ll get a shell prompt (as root). Inside the container you can run Linux commands (e.g. apt update, ls, etc.) independently of your host. Type exit to leave the container shell; that stops the container.

Start an Nginx web server container bound to port 80.

You can also run services in detached mode. For example, start an Nginx web server container bound to port 80:

docker run -d -p 80:80 --name myweb nginx

This downloads the nginx image and runs it in the background (-d), mapping container port 80 to host port 80. In your web browser, enter the IP address of your server to test (or with curl localhostor curl remote_ip), you should see the Nginx welcome page. (Stop it with docker stop myweb.)

Congratulations, you now have a working Docker host and have run your first containers!

Next Steps

With Docker set up, you can now explore many Linux server projects in containers. The Linuxblog.io articles What’s Next After Installation and DIY Projects for Linux Beginners provide great inspiration. For example, you could use Docker to:

  • Host a personal website (e.g. Nginx or Apache) in a container.
  • Run a media server like Plex or Jellyfin to stream your videos/music.
  • Deploy a cloud storage app (Nextcloud/ownCloud) for self-hosted file syncing.
  • Set up a VPN or ad-blocking service (OpenVPN, Pi-hole) on your home network.
  • Run a database (MySQL/PostgreSQL) container and connect it to your apps.
  • Self-host development tools (GitLab/Gitea for Git, Jenkins for CI) in Docker.
  • Create a home automation server (Home Assistant) in a container.
  • Experiment with containerized firewalls or monitoring tools.
  • Oh, also observability. See: Observability – 20 Free Access and Open-Source Solutions.

Each of these projects builds on the Linux home server skills discussed in those articles.

Conclusion

Setting up Docker allows a complete shift in how you can manage, deploy, and scale applications across Linux systems. Whether you’re tinkering with a VM, wrestling with a home server, or building out a full lab environment, containers offer this beautifully clean and consistent way to run services without all the overhead headaches. This used to keep me up at night.

Now that your Docker host is up, you’re ready to start exploring. As you move forward, Docker becomes this incredibly flexible foundation. Keep building, keep breaking things (safely, of course), and keep learning. That’s where the real magic happens. I am, I know I will be!

Tags: , , ,



Top ↑