Docker

Also see docker cheatsheet.

  • written in Go
  • client-server architecture
    • docker is the client, dockerd (daemon) is the server

Images

  • An image is a private file system just for your container, which provides all the needed files and code
    • filesystem, app dependencies, configuration (e.g. environment variables, metadata), scripts, binaries.
  • Images are often based on other images
  • A Dockerfile describes the steps to create an image, where each instruction creates a "layer" in the image
  • Speed: if you change an instruction, only the affected layer is updated!
  • Images are stored in docker registries
    • docker pull
    • docker push

Container

  • Sandboxed process isolated from other OS processes
    • uses kernel namespaces and cgroups
  • Runnable instance of an image
  • Relatively isolated from other containers and host machine by default, but this is configurable.
  • Filesystem: a container gets its own "scratch space", but updates won't be seen in other containers even if they are using the same image.

What happens when you run docker run -i -t ubuntu /bin/bash?

  1. Pulls ubuntu image from configured docker registry unless it's already available locally
    • i.e. docker pull ubuntu
  2. Creates a new container for running the image
    • i.e. docker container create
  3. Allocates read-write (local) filesystem
  4. Creates a default network interface, incl. assigning an IP to the container
    • By default, docker containers can use the host machine's network to connect to external networks
  5. After the container is started, /bin/bash is executed
  6. -t starts a container
    • -i starts an interactive session where you can input in the terminal and the output gets back