Docker Containers and Images : Part 1
I started learning docker few days back and got confused when it came to differentiating docker containers and images. In a simple definition docker image is manifest or snapshot of container and a container is instance of docker image.
Lets dig into images a bit, We all need a Dockerfile
to build an image and we all know that Dockerfile
contains commands like FROM
, WORKDIR
, CMD
, RUN
, EXPOSE
etc. And we all have seen docker creates layer for each command written in Dockerfile
on top of last command, so far so good!
Lets create a simple docker file
And execute docker image build -t test001 .
So all commands are getting executed step wise. but wait, what is this
Running in 788788020b27
after step 3 and there is another lineRemoving intermediate container 7887888020b27
. hmm.. seems like there is a container executing on top of each layer and its result is getting committed as a snapshot for next step.
So I executed my next command
docker image build -t test001 --rm=false .
Now I do not see any Removing intermediate container and executing docker container ls -a
command gives below result
All the containers for each layer is present as stopped container. Now what docker container run
do? It creates another R/W layer on top of top layer of image.
So the major difference between image and container is this Thin R/W layer.