What is the difference between an image and a container?
An image is a read-only template - the app, its dependencies and configuration, built in layers from a Dockerfile. A container is a running instance of an image with its own writable layer on top. One image can run as many containers.
docker build -t myapp:1.0 . # build an image from the Dockerfile
docker run -d --name web1 myapp:1.0 # start a container from it
docker run -d --name web2 myapp:1.0 # a second container, same image
docker ps # list running containersSaying changes made inside a container change the image. They do not - they are lost when the container is removed, unless you use a volume or build a new image.
- What is an image layer, and why does layer order matter?
- What happens to a container's data when it stops, and when it is removed?