paint-brush
Docker Image vs. Container: What Are the Differences?by@shelley
321 reads
321 reads

Docker Image vs. Container: What Are the Differences?

by Shelley BenhoffMay 3rd, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Docker allows developers to quickly spin up any development environment without having to install all of the software and tools necessary on their local machine. We will discuss this topic in depth during this course and you will build base images and work with the builder pattern and multi-stage builds.
featured image - Docker Image vs. Container: What Are the Differences?
Shelley Benhoff HackerNoon profile picture

Docker allows developers to quickly spin up any development environment without having to install all of the software and tools necessary on their local machine. This is accomplished using images and containers, but what does that mean?


Today, I’m going to explain the difference between a docker image vs container.


What Is a Docker Image?

An image is a package containing the information needed to create a container. It includes all the dependencies and deployment configurations that are used at container runtime. Images can inherit from multiple base images using layering.


We will discuss this topic in depth during this course, and you will build base images and work with the builder pattern and multi-stage builds layers stacked on top of each other to form the container's filesystem. An image does not have a state, and it never changes.


If you were working in your local development environment, to get started with any project, your first step used to be installing everything you need for the project you’re working on such as your SQL server, IIS, search index provider like Solr, etc. This process is error-prone and tedious.


Docker images include all of those tools which means that when you start on a new project, the developers on the team would simply pull the docker image! It’s honestly the best thing ever.

What Is a Docker Container?

On the other hand, a container is a runtime instance of an image. It has an image, execution environment, and instructions for runtime such as doing a nuget restore and building the solution using MSBuild.


The idea behind Docker is that it defines a standard to ship software. Containers refer to Shipping Containers which define a standard to ship goods globally.


Those goods arrive at a dock, and a dock worker (also known as a docker) is the person who loads and unloads goods from shipping containers.


I was working with Docker for over a year before I heard this, and I wanted to pass it on! Let’s take a look at this in practice!

How to Pull a Docker Image and Run a Docker Container

I’m going to use the static-site example. You can get this from the docker-curriculum repo using the run command shown here. I use the Docker extension in VSCode to work with Docker images and containers, and I highly recommend it.

docker run -d -P --name static-site prakhar1989/static-site

How to Get the Port Number for a Running Docker Container

You will need to get the port for your static site using the docker port command and specifying the static-site container.

docker port static-site


Open a browser, and navigate to your localhost and port number.

Navigate to the localhost and port for your running docker container

Using the Docker Extension in VSCode

I like to use VSCode to work with my Docker containers, and if you install the extension, you can manage your containers, images, registries, networks, volumes, and contexts. You can expand the images and containers panels to see what you have created!


The name of the image and container is the same: prakhar1989/static-site. However, the container can be referenced by the shorter name or tag “static-site.”


You can also view your containers using the command docker ps. This will show you valuable information about your container including the status and ports.


To view all images, use the command docker images.

Working with Docker image vs. container in VSCode using the Docker extension

In summary, a Docker image is a package that includes all the dependencies and deployment configurations that are used at container runtime. A container is the runtime instance of an image.


First published here