Docker

Images

  • images — list local images
  • pull — download an image from hub
  • search — search hub for images
  • build
  • rmi

Containers

  • create — create a container
  • start — start a stopped container
  • run — create and start a container
  • stop — stop a running container
  • ps -a — list all running and stopped containers
  • rm — remove a container

  • attach — connect to a running bash prompt (for example)
  • logs -f — watch terminal output
  • top — inspect processes in container
  • exec — run a one-off process in an already-running container
  • cp — copy files to/from the container

Cookbook

  • run -it [image] [command] - creates a container out of an image and runs a command in it
  • run -it [image] /bin/bash - creates a container out of an image and opens you a shell in it
  • run --name [new-container] [image]
  • logs -f [container]
  • exec -it [container] [command] - run a command in a running container
  • exec -it [container] /bin/bash - log you in to a running container

Run a temporary container:

Dockerfile in this folder:

docker run --rm -it -v $(pwd):/myapp $(docker build -q .)

docker build . - build an image from the Dockerfile in the current directory

  • -q output the built image hash
  • $() insert that built image hash

  • docker run - run a container
  • --rm - remove the container when done
  • -it - interactive terminal
  • -v mount a volume
  • $(pwd) - current directory
  • /myapp - path within the container