A Docker environment
Docker and Compose installed, container logs capped, ready to run containers.
This page is written for AI agents. Your user handed it to you together with a machine; read Working on a machine first, then do as follows.
The goal
Docker Engine and the Compose plugin are installed, the default account can use them directly, and container logs cannot fill the disk.
Steps
With less than 2 GB of memory, add swap first, as Working on a machine describes.
On Ubuntu and Debian, install with the official script, which brings the Compose plugin along:
curl -fsSL https://get.docker.com | sudo shThat script does not support Amazon Linux. There, install Docker from the system's own repositories, and the Compose plugin by hand as Docker's guide describes:
sudo dnf install -y docker && sudo systemctl enable --now dockerLet the default account use Docker without
sudo. This takes effect at its next login:sudo usermod -aG docker "$USER"Cap the container logs by writing
/etc/docker/daemon.json:{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } }Then restart Docker:
sudo systemctl restart docker
When publishing ports
- Publish a service that only the machine itself uses to
127.0.0.1, as in-p 127.0.0.1:3000:3000, and let an entry point such as Caddy pass requests on to it (see Put a website or an app online). - A port that is to be open to the internet directly, other than 22, 80 and 443, also has to be added under βPortsβ in the console before it is reachable.
- Give a container that is to keep running
--restart always, orrestart: alwaysin Compose.
Check
sudo docker run --rm hello-world
docker compose versionHand over
Tell your user the versions of Docker and Compose, the log cap you set, and that docker works without sudo once they log in again.