Docker: images and containers

Image, container, registry, tag and daemon; the commands pull, run (-d, -p, -e, --name, --rm), ps, stop, start, rm, logs, exec, images and rmi; container states and port publishing.

  • 30 cards
  • 6 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. The steps
  5. Scenarios
  6. Understand

A few cards from the deck

  • Docker image: what is it?

    Show the answer

    A read-only template, built in layers, from which containers are created.

    As many containers as wanted can be created from one image: it never changes, each container adds its own writable layer.

  • Which command starts nginx in the background, named web, reachable on the host's port 8080?

    • docker run -d --name web -p 8080:80 nginx
    • docker run -d --name web -p 80:8080 nginx
    • docker run -d --name web -e 8080:80 nginx
    • docker run --rm --name web -p 8080:80 nginx
    Show the answer

    docker run -d --name web -p 8080:80 nginx

    -d detaches, --name names, -p host:container publishes. nginx listens on 80 inside the container, hence 8080:80. The variant without -d keeps the terminal busy, and -e sets an environment variable, not a port.

  • With -p 8080:80, port … of the host is forwarded to port … of the container.

    Show the answer

    With -p 8080:80, port 8080 of the host is forwarded to port 80 of the container.

    The order is always host then container. -p 80:8080 would do the opposite: open the host's port 80 towards a container listening on 8080.

  • Docker container: what is it?

    Show the answer

    A running instance of an image: an isolated process with a writable layer of its own, deleted only along with the container.

    Image and container are much like a class and an object: the template, then its instances.

  • A container's life cycle: which step comes after "docker create --name web nginx → the container exists, state created"?

    • docker start web → state running
    • docker pause web → state paused
    • docker unpause web → back to state running
    • docker stop web → state exited
    Show the answer

    docker start web → state running

    A container goes through created, running (or paused) then exited, and is only erased by docker rm. docker run chains create and start.