Now let's see the difference between a docker image & a docker container.

Note that Docker container and Docker images are two separate things and are not interchangeable in any means. Let’s go through the basic definitions & differences of both.

Docker Images

  • Docker Image is a combination of file system and parameters & you can think of it as a single package that holds up everything you need to run your application. You can also refer a docker image as a MAGIC file.
  • A Docker image doesn’t have any state attached to it and once built it never changes.
  • A Docker image is something that you can download, build and run.
  • You can also consider a Docker image as a result of running a series of steps.

Docker Containers

  • On the contrary, The act of running a Docker image is called container. In developer’s perspective, you can think of a Docker image as a class and Docker container as an instance of the class. Like first you define a class then you create an instance of it.
  • You can launch many containers from a single image. For example if you’ve a single image of your web application
  • Docker Containers are immutable, means that any changes you make on them while running will be lost forever when you stop that container.

For example, let’s run a simple linux container by:

docker run -it alpine sh

and make a new folder in the home directory and exit and rebuild the container and you’ll see there’s no such file in the home directory. Hence Docker containers are immutable.

You may also Like