Download an image from registry
Images · Pattern / syntaxdocker pull <image> Search code, tasks or categories in English or Spanish. Copy a snippet and adapt it to the stated context.
Showing 61 of 61 commands
Run Docker CLI commands in a terminal with Docker installed and its engine available. Replace <…> placeholders with your own values before running. Dockerfile instructions belong in a Dockerfile; Compose commands require a Compose project. Copying does not execute a command. Read the notes on commands that remove data.
docker pull <image> docker images docker rmi <image> docker image prune -a With -a, this includes unused tagged images, not only dangling images. Review before running; an image referenced by a container is kept.
docker build -t name:tag . docker build --no-cache -t name . docker tag src:latest user/src:1.0 docker push user/image:tag docker history <image> docker save -o backup.tar image docker load -i backup.tar docker run <image> docker run -d --name web nginx docker run -it ubuntu bash docker run -p 8080:80 nginx docker run -v /host:/container image docker run --rm image docker run -e KEY=value image docker run --env-file .env image docker ps docker ps -a docker stop <container> docker start <container> docker restart <container> docker rm <container> docker rm -f <container> docker container prune docker exec -it <container> bash docker logs <container> docker logs -f --tail 100 <container> docker inspect <container> docker stats docker cp file container:/path FROM node:24-alpine Node.js 24 is an official supported LTS image line. Alpine uses musl libc; check compatibility if your dependencies include native modules.
WORKDIR /app COPY . . COPY package*.json ./ RUN npm install When package-lock.json is committed, prefer npm ci for a clean install from the lockfile; keep package.json and the lockfile in sync.
ENV NODE_ENV=production EXPOSE 3000 CMD ["node", "server.js"] ENTRYPOINT ["/app/start.sh"] This is exec form: docker run arguments are passed to the entrypoint. Shell form behaves differently, ignores CMD/run arguments, and can prevent the process receiving stop signals.
ARG VERSION=1.0 USER node HEALTHCHECK CMD curl -f http://localhost/ || exit 1 Only works if curl exists in the image and the app serves this URL. Use a health endpoint and a probe available in your image.
docker compose up docker compose up -d docker compose down docker compose down -v This removes named volumes declared by the project and attached anonymous volumes, deleting their data. External volumes are kept. Check the Compose file and back up needed data first.
docker compose ps docker compose logs -f service docker compose build docker compose exec service bash docker compose restart service docker network ls docker network create mynet docker run --network mynet image docker volume ls docker volume create mydata docker volume prune By default, removes unreferenced anonymous local volumes. Add -a to include named volumes; either can contain data you still need.
docker system prune -a -a includes all unused images, not only dangling ones. This also removes stopped containers, unused networks and build cache. Volumes are not included unless --volumes is added (then unused anonymous volumes are pruned). Review before running.
Docker launched in 2013, and its commands are now widely used to build and run container images. This cheatsheet covers 60+ commands across images, containers, Dockerfile instructions, Compose, networks, and volumes. A `COPY . .` before dependency installation can invalidate that layer whenever source files change, so Docker reruns the install and every later layer. Copy dependency manifests first, install dependencies, then copy application code. A bind mount such as `-v /host:/container` hides files already present at the container path while the mount is active. `docker system prune -a` removes stopped containers, unused networks, unused images (not only dangling images), and build cache; volumes are excluded unless `--volumes` is added, which prunes unused anonymous volumes. Check the cleanup scope before running it.
A few patterns earn their place near the top of any Dockerfile. Order instructions from least to most frequently changing so earlier layers can be reused: base image, system packages, dependency manifests (`package*.json`, `requirements.txt`, `go.mod`), the matching install step, then application source. For npm projects with a committed `package-lock.json`, `npm ci` installs from that lockfile. With exec-form `CMD`, the command and arguments are defaults that runtime arguments can replace. An exec-form `ENTRYPOINT` sets the executable and receives runtime arguments; shell form behaves differently and can prevent the process from receiving stop signals. A `.dockerignore` file keeps files such as `node_modules`, `.git`, and build artefacts out of the build context. `EXPOSE` documents a listening port but does not publish it — only `-p` or Compose `ports:` makes it reachable from the host. The cheatsheet groups these topics so the right section is easy to find.
Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).
By Marco B. ·