Docker Container vs Image
If you are wondering what the difference is between a Docker container vs image then you have come the right place. A container is just a running instance of an image. A Docker image is used to create an actual Docker container. The image can be thought of kind of like a blueprint. It is an image of a system. A container is the actual runnable system. It can be thought of kind of like a light weight VM. You can have many containers based on a single image.
Here are a couple good analogies:
- An image is like a recipe and a container is like a cake. ( You make multiple cakes from the same recipe. )
- An image is like a blueprint and a container is like a house. ( You can build lots of identical houses. )
You would create an image containing everything you usually need to run your application. For example, you might create an image of an Ubuntu system that runs NGINX and includes HTML and PHP files. You would then use this to create multiple running containers spread across multiple machines in a cluster.
Here are some commands that will help you see what containers and images you have on your system.
docker images | Show images |
docker ps | Show running containers |
docker ps -a | Show stopped |
Docker Container vs Image Example Video
Images: Where Do They Come From?
Docker images can come from a few different places. These include:
- Pull down from a registry (ex: Docker Hub)
- Build from a Dockerfile
- Import image from a tar ball
- Load an image from a tar ball
- Save a snapshot of a running container as an image
Containers: Where Do They Come From?
Containers come from images. When you create or start a container, you specify an image that it will be created from.
The following two commands will create and run two containers called “smelly-hippo” and “funny-frog” based on the image “ubuntu”.
docker run -tid --name smelly-hippo ubuntu
docker run -tid --name funny-frog ubuntu
You can also create a container without running it like this:
docker create -ti --name smelly-hippo ubuntu
References