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.
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:
FROM ubuntu:18.04COPY . /appRUN make /appCMD 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.