FahamLah

Docker commands

One page per command. What it does, when to use it, how risky it is.

Your laptop (D0 basics)

  • curlAsks an address for a page and prints the answer.Risk: Safe
  • chmodChanges who may read, write or run a file.Risk: Safe
  • exportSets an environment variable for the programs you start here.Risk: Safe
  • psLists processes: programs that are running now.Risk: Safe
  • echoShows the exit code of the last command.Risk: Safe

Run containers

  • docker versionShows the Docker client and engine versions.Risk: Safe
  • docker runMakes a new container from an image and starts it.Risk: Safe
  • docker psLists running containers.Risk: Safe
  • docker stopAsks a container to stop, then forces it after 10 seconds.Risk: Safe
  • docker portShows which laptop ports lead into a container.Risk: Safe

Look inside

  • docker logsShows what a container printed.Risk: Safe
  • docker execRuns a command inside a running container.Risk: Safe
  • docker inspectShows everything Docker knows about a container, image, volume or network.Risk: Safe
  • docker topLists the processes running in a container.Risk: Safe
  • docker infoShows how the Docker engine is set up: runtimes, storage, cgroups and security.Risk: Safe
  • docker diffLists the files a container added (A), changed (C) or deleted (D) on its top sheet.Risk: Safe
  • docker cpCopies files between your laptop and a container.Risk: Careful

Images and recipes

  • docker imagesLists the images on your machine, with their size.Risk: Safe
  • docker pullDownloads an image from a registry.Risk: Safe
  • docker buildTurns a Dockerfile (the recipe) into an image.Risk: Safe
  • docker historyShows the layers of an image and what made each one.Risk: Safe
  • docker tagGives an image another name. Nothing is copied.Risk: Safe
  • docker buildx buildBuilds one image for several CPU types (platforms) at once.Risk: Safe

Lockers and phone lines

  • docker volumeManages volumes: lockers that keep data after containers go.Risk: Careful
  • docker networkManages networks: phone lines between containers.Risk: Safe

Set meals (Compose)

Share images

  • docker loginLogs in to a registry. Use an access token, not your password.Risk: Careful
  • docker pushUploads an image to a registry.Risk: Careful
  • docker scoutChecks an image's packages for known holes (CVEs). Needs a Docker login.Risk: Safe
  • docker buildx imagetools inspectReads an image in a registry: its digest, platforms and attestations.Risk: Safe

Clean up

  • docker rmDeletes a stopped container and the files inside it.Risk: Can lose work
  • docker rmiRemoves an image name, and the image when no name is left.Risk: Careful
  • docker system dfShows how much disk images, containers, volumes and cache use.Risk: Safe
  • docker system pruneDeletes stopped containers, unused networks, dangling images and build cache.Risk: Can lose work