Install Docker engine add a user and run Docker Compose on Ubuntu
If you want containers on your Ubuntu laptop or VM without the usual hair pulling, this guide walks through installing Docker and Docker Compose for local container workflows. You will get the engine installed, a non root user setup, the Compose tool ready, and a tiny compose file to actually run something. No nonsense, just commands that work on most Ubuntu releases.
Install the Docker engine
Use the Ubuntu packages for a fast and reliable start. These commands install the docker engine package available in the distro repositories and enable the service so it starts now and on reboot.
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker
Yes this is the quick method. If you later want the official Docker repo for the latest features you can switch, but this will get your containers running for development without fuss.
Enable user access to Docker
Running docker as root gets old fast and it makes CI logs look mean. Add your user to the docker group so you can run container commands as your normal user.
sudo usermod -aG docker $USER
After that either log out and log back in, reboot, or run newgrp docker
in the terminal to pick up the group change immediately. This avoids typing sudo for every single docker command.
Install Docker Compose
Compose lets you declare multi container setups so your app does not rely on a complex shell script or voodoo. On many Ubuntu releases the compose package is available via apt.
sudo apt install -y docker-compose
Modern Docker also ships a compose plugin that is used as docker compose
with a space, while older installs use the docker-compose
binary with a dash. For local dev either approach works, just be consistent in scripts and CI.
Create a docker compose file
Start small. Create a file named docker-compose.yml
and define one service before you try to orchestrate the entire internet. Here is a minimal example running a simple web service.
version: '3.8'
services:
web:
image: nginx:stable
ports:
- 8080:80
volumes:
- ./site:/usr/share/nginx/html:ro
This declares a single service using the nginx image, maps port 8080 on the host to port 80 in the container, and mounts local content for quick iteration.
Run and manage containers
Bring the stack up in the background and peek at logs like a responsible operator.
docker compose up -d
docker compose ps
docker compose logs -f web
If your install uses the older command name use docker-compose
instead of docker compose
. The commands are otherwise the same and the behavior is predictable, unlike that one mystery config you never touched.
Common troubleshooting
- Permission denied when running docker commands after group change? Log out and back in or run
newgrp docker
. - Compose file not picked up? Check the filename and indentation. YAML hates tabs and bad attitudes.
- Want latest features? Consider installing the official Docker packages from Docker for Linux documentation.
Tips for less pain in staging and production
- Pin image tags to avoid surprise updates breaking everything overnight.
- Run on a recent stable kernel for better compatibility with container runtimes.
- Keep your compose files in version control and back up important configs.
That is the gist. You installed the engine, allowed a non root user to run containers, got Compose installed, wrote a basic compose file, and started a service. Now go build something useful or at least break it in a structured way. Welcome to containerization.