Today, you will learn the basics of Docker.

StackOverflow called it one of the most universally used tools this year.

docker growth graph

Developers are obsessed with it.

But why? Is it that useful?

Why Docker

Imagine this.

You have a working Python code on your computer.

python code

You send it to a friend.

python code

But for some reason

python code
python code

What happened?

You found out that he's still using Python 2!

The code that works on your machine COULD FAIL, just because it’s in another environment.

Aka the “it works on my machine problem.”

Docker fixes that by packaging your code into containers.

Docker Containers

Containers are like mini computers.

It contains everything your program needs.

docker container

So your code runs the exact same way on any machine.

docker containr in host computer

A container isn’t something magical. It’s just a process running on your computer that has its own filesystem, network, etc.

Basic Docker Workflow

To make a container, first create a Dockerfile (the filename is literally Dockerfile).

create a dockerfile

Inside, specify everything required to run your code.

dockerfile

Python 3.11, a Linux-based environment, command: “python main.py”

You could just send your friend the file & your code and tell him to build a container based on that.

But there's a better way: build a Docker Image.

build a docker imge

A Docker image is a static, shareable version of your environment.

It’s very easy to create, just run this command:

docker build -t my_app .
share the docker image

After you share the image, your friend can run your code easily by creating a container.

create a container

He doesn't even have to install Python. He just has to run one command:

docker run my_app

Docker will create a container on his computer based on the image.

Now your code works on his machine, or any other.

Fee from Anime Coders

How did you like today's email?

Login or Subscribe to participate

Keep Reading