[docker] What is the difference between a Docker image and a container?

It may help to think of an image as a "snapshot" of a container.

You can make images from a container (new "snapshots"), and you can also start new containers from an image (instantiate the "snapshot"). For example, you can instantiate a new container from a base image, run some commands in the container, and then "snapshot" that as a new image. Then you can instantiate 100 containers from that new image.

Other things to consider:

  • An image is made of layers, and layers are snapshot "diffs"; when you push an image, only the "diff" is sent to the registry.
  • A Dockerfile defines some commands on top of a base image, that creates new layers ("diffs") that result in a new image ("snapshot").
  • Containers are always instantiated from images.
  • Image tags are not just tags. They are the image's "full name" ("repository:tag"). If the same image has multiple names, it shows multiple times when doing docker images.

Examples related to docker

standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker What is the point of WORKDIR on Dockerfile? E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation How do I add a user when I'm using Alpine as a base image? docker: Error response from daemon: Get https://registry-1.docker.io/v2/: Service Unavailable. IN DOCKER , MAC How to fix docker: Got permission denied issue pull access denied repository does not exist or may require docker login Docker error: invalid reference format: repository name must be lowercase Docker: "no matching manifest for windows/amd64 in the manifest list entries" OCI runtime exec failed: exec failed: (...) executable file not found in $PATH": unknown

Examples related to docker-container

How to assign more memory to docker container How to rebuild docker container in docker-compose.yml? How to access host port from docker container How do I get into a Docker container's shell? Docker - Container is not running What is the difference between a Docker image and a container? How to copy files from host to Docker container? Docker: Copying files from Docker container to host How to deal with persistent storage (e.g. databases) in Docker

Examples related to docker-image

Can't create a docker image for COPY failed: stat /var/lib/docker/tmp/docker-builder error Can’t delete docker image with dependent child images How to remove old and unused Docker images Stopping Docker containers by image name - Ubuntu docker run <IMAGE> <MULTIPLE COMMANDS> What is the difference between a Docker image and a container? Where are Docker images stored on the host machine? Run a Docker image as a container