What Are Docker Images, -Files And Containers

Docker

14/06/2021


The best way to understand what Docker images, -files and containers are, is to understand how to they relate to each other. For that, I found an image (pun intended 😝) that does a great job of demonstrating this.

Process to create a Docker container

Process of creating a container

Dockerfile

A Dockerfile is simply a text file that contains instructions on how to build an image. In it, you specify the things you'd like to use, such as software dependencies and your custom code. The instructions look something like this:

TEXT
FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py

The software dependencies that you specify (e.g. Ubuntu in this example) will be Docker images themselves pulled from the official repository.

Afterwards, you run the docker build command to create an image from the file.

Docker image

In my mind, 🧠 images are simply idle containers that have everything installed (e.g. Node.js and my custom code) and include instructions on how to launch the entire application.

It's much like your laptop, which has a bunch of tools installed and contains your programming project, but it isn't running yet!

From an image, you then create a Docker container with docker run.

Docker container

With a better understanding of Docker images, containers are nothing more than a running instance of your image. Things are actually happening inside the container.

You can stop, restart, move or delete the container, and even create a new image based on the current state of your container.


WRITTEN BY

Code and stuff