Today, you will learn the basics of Docker.

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

Developers are obsessed with it.

But why? Is it that useful?

Why Docker

Imagine this.

You have a working Python code on your computer.

You send it to a friend.

But for some reason

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.

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

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).

Inside, specify everything required to run your code.

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.

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 .

After you share the image, your friend can run your code easily by creating 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

Login or Subscribe to participate

Keep Reading