GoGetSpace Engineering Last tested 10 min readTested onUbuntu 24.04AlmaLinux 9Fedora 45
Short answer
Install Docker from Docker's own repository, not your system's packages. On Ubuntu or Debian, add the repository and run sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. On AlmaLinux, Rocky or Fedora, add Docker's repository, install the same packages with sudo dnf install, then start Docker with sudo systemctl enable --now docker. Check it with sudo docker run hello-world. Docker Compose comes with it as docker compose.
Containers that publish a port skip your firewall. A port you publish with Docker is open to the internet even if UFW or firewalld has no rule for it. See Keep ports private below.
Install Docker
These are Docker's official steps. They install Docker Engine, the docker command and the Compose and Buildx plugins.
Already installed Docker from your system's packages (docker.io, docker-compose or podman-docker)? Remove those first with sudo apt remove or sudo dnf remove. On a new server you can skip this.
Type y to confirm the install, and again when dnf asks to import Docker's GPG key. Check that the fingerprint is 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35. Unlike on Ubuntu, Docker doesn't start until you run the last command, which also starts it at every boot.
Type y to confirm the install, and again when dnf asks to import Docker's GPG key (fingerprint 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35). Docker doesn't start until you run the last command, which also starts it at every boot. We tested on AlmaLinux. These are Docker's steps for Rocky Linux.
Type y to confirm the install, and again when dnf asks to import Docker's GPG key. Check that the fingerprint is 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35. Fedora may also ask to import its own Fedora key: type y again. Unlike on Ubuntu, Docker doesn't start until you run the last command, which also starts it at every boot.
Fedora comes with Podman installed. Docker installs next to it without problems.
Check that it works
Bash
$ sudodocker run hello-world
Output
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
...
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
If you see Hello from Docker!, Docker works. Check the versions:
Bash
$ docker--version$ docker compose version
Output
Docker version 29.10.1, build c48360f
Docker Compose version v5.8.1
Use Docker without sudo
Right now you need sudo for every Docker command. Without it, docker ps fails with permission denied. Add your user to the docker group:
Bash
$ sudousermod-aG docker $USER
This takes effect at your next login, so log out and SSH in again. Or, to use it straight away in this terminal only (other open sessions still need a new login):
Bash
$ newgrp docker
Then check that it works without sudo:
Bash
$ docker ps
Output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Limit the size of container logs
By default Docker keeps every line a container logs, forever. On a small disk that can fill up your server. Limit each container's logs to 3 files of 10 MB:
Restarting Docker stops all running containers, and those without a restart policy stay stopped, so it's best to do this before you run any apps. The limit only applies to containers created after the restart. Existing containers keep unlimited logs until you remove and create them again (with Compose: docker compose up -d --force-recreate).
Run your first app with Compose
Compose starts containers from a compose.yaml file. This one runs Nginx:
The first time, Docker downloads the image, then starts the container:
Output
Network hello_default Created
Container hello-web-1 Created
Container hello-web-1 Started
Bash
$ curl-I http://127.0.0.1:8080
Output
HTTP/1.1 200 OK
restart: unless-stopped brings the container back after a reboot. We tested it: after a reboot, the container was running again by itself. To stop and remove it, run docker compose down in the same folder.
Keep ports private
When you publish a port like "8080:80", Docker opens it to the whole internet. It adds its own firewall rules, which come before UFW and firewalld. We tested this on all three systems: the port was reachable from outside even though the firewall had no rule for it.
To keep a container private, publish it on 127.0.0.1 only, like the example above:
YAML
ports:-"127.0.0.1:8080:80"
If the container is already running, run docker compose up -d again to apply the change.
Then only programs on the server itself can reach it. To put a website online, install Nginx on the server and set it up to forward requests to http://127.0.0.1:8080 (a reverse proxy). Open ports 80 and 443 in your firewall, then add HTTPS with Let's Encrypt. Publish a port to everyone ("80:80") only when you really want it open.
Databases (5432, 3306, 6379, 27017) should never be published to everyone. Use 127.0.0.1, or no ports at all if only other containers need them.
If it doesn't work
What you see
What to do
permission denied when you run docker
Your user isn't in the docker group yet, or you haven't logged in again since. Log out and back in, or run newgrp docker. Or use sudo docker.
Cannot connect to the Docker daemon
Docker isn't running. Start it with sudo systemctl enable --now docker. On AlmaLinux, Rocky and Fedora it doesn't start until you do this once.
port is already allocated
Another container or program already uses that port. Pick another port, or stop the other one. The failed container stays behind with the status Created. Find its name with docker ps -a and remove it with docker rm followed by that name. With Compose, fix the port in compose.yaml and run docker compose up -d again.
The disk is filling up
Old images, stopped containers and logs. Check with docker system df, clean up with docker system prune. It asks first, then deletes stopped containers, unused networks and unused images. Your volumes (data) are kept. Also limit container logs.
A container is reachable from the internet without a firewall rule
Use docker-ce from Docker's repository, as above. docker.io (Ubuntu and Debian) and moby-engine (Fedora) are built by the distribution and are often older. Don't install both.
What's the difference between docker compose and docker-compose?
docker compose (with a space) is the current version, installed above as a plugin. docker-compose (with a dash) is the old standalone version, which is no longer updated. Most guides that use docker-compose work the same with docker compose.
How do I update Docker?
With your normal system updates: sudo apt update && sudo apt upgrade on Ubuntu and Debian, or sudo dnf upgrade on AlmaLinux, Rocky and Fedora. Updating Docker restarts it. Containers with restart: unless-stopped (or another restart policy) start again by themselves. Containers without one stay stopped until you start them.
Is Docker free?
Yes. Docker Engine, the part you install on a server, is open source and free to use. Docker Desktop's paid plans are for the desktop app on Windows and Mac, not for servers.
Can I use Podman instead?
Yes. Podman runs most Docker images. It comes with Fedora and is available on AlmaLinux and Rocky. This guide covers Docker, because most app instructions assume it.
Type y to confirm the install, and again when dnf asks to import Docker's GPG key. Check that the fingerprint is 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35. Unlike on Ubuntu, Docker doesn't start until you run the last command, which also starts it at every boot.
Type y to confirm the install, and again when dnf asks to import Docker's GPG key (fingerprint 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35). Docker doesn't start until you run the last command, which also starts it at every boot. We tested on AlmaLinux. These are Docker's steps for Rocky Linux.
Type y to confirm the install, and again when dnf asks to import Docker's GPG key. Check that the fingerprint is 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35. Fedora may also ask to import its own Fedora key: type y again. Unlike on Ubuntu, Docker doesn't start until you run the last command, which also starts it at every boot.
Fedora comes with Podman installed. Docker installs next to it without problems.
These are Docker's official steps for Debian. We tested the Ubuntu version, not Debian. Docker should start by itself after the install, and at every boot.
These are Docker's official steps for Debian. We tested the Ubuntu version, not Debian. Docker should start by itself after the install, and at every boot.