docker run command and the matching compose.yaml, or paste a docker run command to have every flag explained and turned into Compose. It warns about the mistakes that hurt later: database ports open to the internet (Docker skips ufw), docker.sock and --privileged, :latest tags, passwords on the command line, and logs that fill the disk.docker ps | Running containers. Add -a to see stopped ones too. |
docker logs -f --tail 100 NAME | Follow a container’s output, starting with the last 100 lines. |
docker exec -it NAME sh | Open a shell inside a running container (bash if the image has it). |
docker compose up -d | Start everything in compose.yaml in the background, or apply changes to it. |
docker compose pull && docker compose up -d | Update: pull newer images, then recreate only the containers that changed. |
docker compose logs -f | Follow the logs of every service in the file. |
docker compose down | Stop and remove the containers and network. Named volumes stay. |
docker stats | Live CPU, memory and network use per container. |
docker system df | Disk space used by images, containers, volumes and build cache. |
docker image prune | Delete dangling images. -a deletes every image no container uses. |
-p 5432:5432 is open to the world even when ufw says the port is closed. Publish on 127.0.0.1: for things only this server should reach.docker compose down -v deletes your data. The -v also removes named volumes, which is where databases keep their files.docker rm, including after compose up recreates it.:latest isn’t “newest”. It’s whatever you pulled last. A later pull can bring a major version with breaking changes.max-size, per container or for all of them in /etc/docker/daemon.json.unless-stopped vs always. Both restart after a crash or reboot. A container you stopped by hand stays stopped with unless-stopped; with always it comes back when the Docker service restarts.$ as a variable. In compose.yaml, write a literal dollar sign as $$. This page does that for you.docker-compose is gone. Compose v1 (the Python one, with a dash) stopped getting updates in 2023. Use docker compose, with a space. The version: line at the top of old files is ignored now.Fill in the image, ports, volumes and variables, or start from a recipe such as PostgreSQL or Nginx, and get both the docker run command and a compose.yaml that does the same thing. Paste an existing docker run command to have each flag explained in plain words and turned into Compose. The Compose files it writes were tested with Docker Compose’s own checker, docker compose config.
Each flag has a Compose key: -p becomes ports, -v becomes volumes, -e becomes environment, --restart becomes restart and --name becomes container_name. Named volumes are also listed at the bottom of the file. Paste the command above to do it automatically, then run docker compose up -d.
Docker writes its own iptables rules for published ports, and they take effect before ufw’s rules. So -p 5432:5432 is open to the internet even when ufw denies port 5432. Publish on 127.0.0.1:5432:5432 when only the server needs it, or don’t publish at all: containers on the same network reach each other by name.
Both restart a container after a crash or a reboot. The difference is a container you stopped yourself: with unless-stopped it stays stopped, while with always it starts again the next time the Docker service starts. unless-stopped is the usual choice.
The default json-file log driver never rotates. Add --log-opt max-size=10m --log-opt max-file=3 to a container, or set "log-opts": {"max-size": "10m", "max-file": "3"} in /etc/docker/daemon.json and restart Docker. The daemon setting applies to containers created after the change.
Put them in an env file that only you can read (chmod 600) and use --env-file or env_file:. Better still, many official images accept a _FILE variable, such as POSTGRES_PASSWORD_FILE, which reads the password from a Compose secret mounted at /run/secrets/.
Related tools: Compose Visualizer · K8s Manifest Builder · All tools A–Z
Most tools run entirely in your browser. Tools marked 📡 contact outside services, as listed in the Privacy Policy. Review commands before you run them; see the Terms.