FOSSFEEDWhere activity matters more than stars. Discover Fire Pit Noted Submit a project
← All articles

How to Install Docker and Portainer on Debian

Get Docker and Portainer running on Debian with this straightforward beginner's guide, including Docker Compose and HTTPS access.

When I first started experimenting with self-hosting, Docker was one of my biggest hurdles. I had heard plenty about containers, but getting everything installed and working was another story.

In this guide, I'll walk you through installing Docker and Portainer on Debian. Docker will handle running our applications, while Portainer gives us a web interface to manage them.

The official Docker documentation is excellent, but I remember how intimidating it looked when I was getting started. I'll keep things simple and explain the commands as we go.

Update Your Debian Server #

Before installing Docker, it's a good idea to make sure your Debian server is up to date. This will install available security patches and package updates.

For this guide, I'm using Debian with a user account that has sudo privileges. If you're logged in directly as root, you can leave sudo out of the commands.

Open your terminal and run the following command:

sudo apt update && sudo apt upgrade -y

This refreshes the package list and installs available updates. If important system components were updated, consider rebooting before continuing.

Install Docker on Debian #

Now we're ready to install Docker. We'll use Docker's official package repository so the installation can receive updates through Debian's package manager.

These instructions are intended for a fresh installation. If you've previously installed Docker or other container packages, check the official Docker documentation for conflicting packages before continuing.

Step 1. Install the required packages.

First, install the tools needed to download Docker's repository signing key.

sudo apt install ca-certificates curl -y

Step 2. Add Docker's signing key

Next, create the directory for repository keys and download Docker's official GPG signing key.

sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc```

Step 3. Add the Docker repository

Now add Docker's official repository to your system. This command automatically uses your Debian release and system architecture.

sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

Step 4. Install Docker and Docker Compose

With the repository configured, we can install Docker Engine, the command-line tools, and Docker Compose.

Compose allows us to define and manage containers using YAML configuration files. We'll be using it later when we start deploying self-hosted applications.

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

Step 5. Verify the installation

Let's make sure Docker is installed and running. First, check the Docker service:

sudo systemctl status docker

You should see active (running) in the output. Press Q to exit the status screen.

Next, run Docker's test container:

sudo docker run hello-world

Docker will download a small test image, run it, and display a confirmation message if everything is working.

Finally, check that Docker Compose is installed:

sudo docker compose version

If the command displays a Compose version, you're ready to go.

One thing worth remembering is that modern Docker Compose uses docker compose with a space. You'll still encounter older tutorials using docker-compose, but the Compose plugin is the recommended approach for new installations.

Step 6. Enable Docker at startup

Docker usually starts automatically after installation, but you can make sure it's enabled at boot with this command:

sudo systemctl enable --now docker

This enables Docker to start after a reboot and starts the service immediately if it isn't already running.

Install Git (Optional) #

Some self-hosted applications are distributed through GitHub, and you may eventually need to download a project's files directly from a repository.

You can install Git with the following command:

apt install git -y

Once installed, you can use git clone to download repositories to your server. You won't need Git for every application, but it's a useful tool to have around.

Install Portainer on Debian #

Now that Docker is running, let's install Portainer.

Portainer gives us a web interface for managing containers, images, volumes, networks, and Docker Compose stacks. It's especially useful when you're getting started and don't want to manage everything through the terminal.

We'll install Portainer Community Edition using its Long-Term Support (LTS) release.

Step 1. Create a Docker volume.

Portainer needs somewhere to store its settings and database. Run this command to create a persistent volume:

sudo docker volume create portainer_data

Step 2. Install Portainer

Now run the following command to download and start Portainer:

sudo docker run -d \
  --name portainer \
  --restart=always \
  -p 9443:9443 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer-ce:lts

Docker will download the Portainer image and create the container.

We're using port 9443 for the HTTPS web interface. You may notice that other tutorials include port 8000, but that's primarily used for Portainer's Edge Agent functionality and isn't needed for this basic setup.

The --restart=always option tells Docker to restart Portainer automatically when appropriate, including after a server reboot.

Step 3. Check that Portainer is running

You can check your running containers with:

sudo docker ps

You should see a container named portainer with a status indicating that it's running.

Step 4. Open Portainer in your browser

Open your web browser and enter your server's local IP address followed by port 9443.

For example: https://192.168.1.5:9443

Replace 192.168.1.5 with your server's actual IP address.

If you don't know your server's IP address, you can find it with:

hostname -I

Portainer uses a self-signed HTTPS certificate by default, so your browser may display a certificate warning. This is expected for a new local installation. Confirm that you're connecting to your own server before proceeding.

Keep Portainer accessible only from your trusted local network or through a secure VPN. Don't forward port 9443 directly to the internet.

Once the page loads, follow Portainer's initial setup process to create your administrator account and connect to your local Docker environment.

Step 5. Secure your Portainer installation

A Quick Note About Security #

Portainer has access to the Docker socket, which gives it powerful control over your server. Treat your Portainer administrator account like any other sensitive system account.

Use a strong, unique password, keep Portainer updated, and avoid exposing its interface directly to the internet.

If you need remote access later, consider a VPN such as Tailscale or WireGuard instead of opening Portainer's management port publicly.

Where Do You Go From Here? #

You now have Docker and Portainer installed on your Debian server. That's a pretty good start!

Spend a little time exploring the Portainer dashboard. Take a look at the containers, images, volumes, and networks sections. You don't need to understand everything right away.

In the next lesson, we'll put Docker and Portainer to work by deploying a self-hosted Ghost blog using Docker Compose.

Ready for the Next Step? #

Now that your server is ready, let's deploy your first application.

Next Lesson: Self-Host a Ghost Blog Using Docker

Comments 0

Join the conversation.

Write a comment

No comments yet. Be the first to comment.

Leave a comment

Anonymous comments are reviewed before publication. Sign in to comment as a member.

Navigation