Install Docker and Compose
Prepare a fresh Ubuntu practice server and verify Docker before adding applications.
Before you begin
Follow the machine setup first. These steps are for a fresh Ubuntu Server 24.04 installation with an internet connection and a user allowed to run sudo. They install software system-wide. If Docker, Podman, or a distribution-provided container runtime is already installed, use the migration instructions in the official Docker installation guide instead of mixing packages.
The three terms
An image is a packaged application and its files. A container is a running instance of an image. Compose reads a YAML file describing several services, networks, and storage, then asks Docker to create them. You need the modern docker compose plugin, not the old docker-compose program.
Install on the practice server
The commands add Docker's signing key and package repository, then install the engine and Compose plugin. Run the entire block in the server terminal. sudo may ask for the password you created when installing Ubuntu. The block between <<EOF and EOF is written into a package-source file.
sudo apt update
sudo apt install ca-certificates curl openssl
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
sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Check the result
sudo systemctl is-active docker
sudo docker version
sudo docker compose version
sudo docker run --rm hello-world
Expected results: active, a Docker client and server version, a Compose version, and the Hello from Docker message. The test container exits after printing its message. Use a maintained Docker Engine version 28 or newer for this guide; older versions have a documented exception to loopback-port isolation. See Docker's port-publishing notes.
Keep using sudo docker in these exercises. Adding a user to the Docker group grants control equivalent to root; it is not a harmless fix for a permissions error. Docker security
If a check fails
- Cannot connect to the daemon: run
sudo systemctl status docker --no-pagerandsudo journalctl -u docker -n 50 --no-pager. Check the service error before restarting it. - Permission denied: use
sudo; do not make the Docker socket world-writable. - Compose is not a command: confirm
docker-compose-plugininstalled successfully. Installing the legacy Python command is not the same repair. - Download or name-resolution failure: check the server's internet connection and DNS before changing the Compose file.
Do not disable Docker's firewall handling or open router ports to make a test work. Published container ports can follow different firewall rules from host services. The next exercise binds them to loopback.
Next: run the practice lab.