Member-only story
Docker Image → A Docker image is an immutable file that contains source code, libraries, dependencies, tools, and other files needed for an application to run(like “my image” from below instructions)
FROM ubuntu:16.0.0
COPY *.properties /app/properties
COPY *.jar /app/jars/
RUN make /app
CMD python /app/app.py
This image is usually built by executing Docker instructions(like above) , which add layers on top of an existing image or os distribution(like ubuntu).
Assume it as ONION with layers(instructions like copy,cmd, from) on top of exisitng image or os distribution(like ubuntu)
So image is just a template(set of instructions) , and cannot run on its own.
Docker container → A container is an instance of an image.So image is like a blue print and the container provides a run time environment to run the image.
Containers are autonomous, they provide strong isolation, ensuring they do not interrupt other running containers, as well as the underlying server that supports it.
We can run image in a container using docker commands like run(docker run <my image>
) or just create a container using commands like create (docker create <my image)
or supply image to container orchestration frameworks based on Kubernetes (like openshift or rancher ), docker Swarm, Apache Mesos.e.t.c.
From object oriented world, image is like a class and container is like object, so as we create multiple objects from same class, we can run multiple containers using same image.