Images and Containers
~240 words ยท 2 min read
Image vs container
The single most important distinction in Docker:
- An image is a read-only template โ a snapshot of a filesystem plus some metadata. Think of it as a class.
- A container is a running instance of an image โ a live process with its own filesystem. Think of it as an object.
One image can launch many containers, just like one class can spawn many objects.
The core commands
docker images # list images on your machine
docker ps # list running containers
docker ps -a # list ALL containers (incl. stopped)
docker pull nginx # download an image from a registry
docker run nginx # create + start a container from nginx
What docker run really does
docker run is two steps combined:
docker createโ makes a new container from the image.docker startโ starts it.
Every docker run you execute creates a new container. Run it twice and you get two containers from the same image.
Stopped containers stick around. Usedocker rm <id>to delete them, or add--rmtodocker runto auto-remove on exit.
Registries
A registry is where images live โ Docker Hub by default, or private ones like GitHub Container Registry, AWS ECR, or a self-hosted registry. docker pull fetches from there; docker push uploads your built images.