Skip to footer content
Iron Academy Logo
Learn C#
Learn C#

Other Categories

Installing Docker and Portainer on Linux

Tim Corey
~18m

Not everything should live directly on your operating system. Tools like SQL Server carry heavy resource footprints, and running them bare-metal means those resources are consumed whether you need them or not. Containers solve this: you spin one up when you need it and stop it when you don't. Docker is the engine that powers this workflow, and Portainer is the lightweight GUI that keeps it manageable without memorizing a library of CLI commands.

This breakdown, based on Tim Corey's Linux development series, details the full setup on Ubuntu: registering the apt repository, setting up the engine, removing the sudo requirement for personal machines, and deploying Portainer CE as a persistent container.

Step 1: Adding Docker's apt Repository

[3:10 - 6:00] Before Docker itself can be installed via apt, you need to register Docker's package source and give your system a reason to trust it. Docker provides a single copyable block of commands that handles all of this in one paste. Head to docs.docker.com, navigate to the Install section, then select Ubuntu. The commands under "Install using the apt repository" are what you want.

That block performs several operations in sequence: it installs the required certificate tooling, downloads Docker's official GPG key, adjusts its permissions, and writes the repository address into your apt sources list. Run the whole block at once by copying it from the docs and pasting it into a terminal with Ctrl+Shift+V.

An important point to emphasize: do not blindly add new package sources. Verify that you trust the source before installing its certificate. Docker is reputable and worth trusting, but the principle applies to every source you add. This approach is actually stricter than what many package managers do by default, which is a feature, not a complication.

Step 2: Installing Docker Engine

[6:00 - 7:10] With the repository registered, installing Docker is a single apt command:

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

Confirm when prompted, and apt handles the download and installation. Docker is configured to start automatically on boot, so it will be running in the background after every restart without any extra steps.

To confirm everything works, run the hello-world container:

sudo docker run hello-world
sudo docker run hello-world
SHELL

Docker pulls the image, executes it, and prints a confirmation message. That output means your installation is working. The hello-world container is designed to run once and exit; it exists purely to verify the engine is responding.

Step 3: Running Docker Without sudo (Personal Machines Only)

[7:45 - 10:30] By default, Docker commands require sudo because managing containers is a privileged operation. On a shared server or production machine, leave this as-is. For a personal development machine you control alone, adding yourself to the docker group removes the prefix:

sudo usermod -aG docker $USER
sudo usermod -aG docker $USER
SHELL

-aG appends the current account to it. Case matters: $USER must be uppercase. The change does not take effect until you log out and back in; a full system restart is often more reliable than a simple log-out for the group membership to apply correctly. Once it does, docker run hello-world works without sudo.

This is a convenience trade-off, not a security improvement. Keep it for development machines only.

Step 4: Creating a Volume for Portainer

[11:30 - 12:45] Before launching Portainer, create a named volume to persist its data across container restarts and replacements:

docker volume create portainer_data
docker volume create portainer_data
SHELL

Containers are ephemeral by design, and destroying one wipes anything stored inside it. A volume lives outside the container lifecycle on a path managed by Docker, so Portainer's configuration survives even if you destroy and rebuild it.

Step 5: Running the Portainer Container

[12:45 - 14:10] Portainer CE is itself a Docker container. The full run command is:

docker run -d -p 9000:9000 --name portainer \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer-ce
docker run -d -p 9000:9000 --name portainer \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer-ce
SHELL

Breaking it down: -d runs the container detached so it stays in the background. -p 9000:9000 exposes host port 9000 and routes it to the matching internal address inside the container. The first -v mounts the Docker socket, giving Portainer visibility and control over your other containers and images. Connecting the socket this way is what allows the GUI to read and manage your entire Docker environment. The second -v links the volume you just created to /data inside the container, persisting its state.

Pull from portainer/portainer-ce (Community Edition). The portainer.io website leads with the paid Enterprise tier, but CE is free and fully capable for local and personal use.

Navigating the Portainer UI

[14:10 - 17:30] Once the container starts, open a browser and go to http://localhost:9000. Portainer prompts you to create an admin password on first access; it must be at least 12 characters. After logging in, click through the quick setup wizard without adding extra environments, then select the local environment from the dashboard.

The home view shows a summary: images downloaded, containers present, networks configured, and volumes in use. Clicking into each section gives you full control. Under Images, you will see hello-world and the Portainer CE image from the two pulls performed during setup. In Containers, both hello-world runs appear in a stopped state alongside Portainer itself, which is actively running.

From the Containers panel you can start, stop, or remove any entry. Selecting a container and clicking Logs shows its output. The hello-world entries display the familiar greeting text from both times it was executed. Restarting a container and checking its logs confirms that new output is appended beneath the first.

Volumes are listed with their mount paths. The portainer_data entry shows its location under /var/lib/docker/volumes/, where the engine stores all named volume data on disk.

Why Portainer Over Docker Desktop

[17:30 - 18:10] Docker Desktop ships with a GUI but carries significant overhead, which matters on a Linux development machine where you want system resources available for your actual workloads. Portainer CE runs as a container itself and consumes far less memory and CPU. It covers the practical needs: browsing images and containers, reading logs, managing volumes, starting and stopping services, all without the weight.

What Comes Next

[17:50 - 18:30] With Docker and Portainer in place, the next step in the series is running SQL Server as a container. A single docker run command pulls the image and starts an instance. From the Portainer containers panel you can stop it when your session ends and restart it when you need it again. This pattern applies equally to Redis and other infrastructure tools that are expensive to run continuously but straightforward to containerise.

Conclusion

[18:30 - end] To recap: register Docker's apt repository with its GPG key, install the engine via apt, optionally add your user to the docker group on personal machines, create a named volume for Portainer, and run the portainer/portainer-ce container mapped to port 9000. From that point, localhost:9000 gives you a GUI that covers the day-to-day work of managing containers on Linux without touching the CLI for routine tasks.

Watch the full video on Tim Corey's YouTube channel to follow the install on a live machine.

Hero Worlddot related to Installing Docker and Portainer on Linux
Hero Affiliate related to Installing Docker and Portainer on Linux

Earn More by Sharing What You Love

Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me