DEV Community

Cover image for Docker: Explained to a 5 year old. ๐Ÿ‘ถ๐Ÿป

Posted on • Updated on

Docker: Explained to a 5 year old. ๐Ÿ‘ถ๐Ÿป

When I was starting out with docker, everything was really difficult for me to figure out. But don't worry. I'm here ๐Ÿ˜‰

Docker is an AMAZING tool that you just can't miss. It's EVERYWHERE!
Docker everywhere

So here's everything you need to know about docker, in ONE blog. Don't worry - I'll keep it very short and concise โšก
I'll walk you through the concepts - Containers, Images, etc. And then we'll write our own Dockerfile to containerize a very simple python application!

Table of Contents

What is docker?

Docker is a way to containerize applications (putting code in boxes that can work on their own). It magically makes a virtual computer, but guess what - they aren't really virtual computers.

Containers are boxes that have no host Operating system, so they are independent of the device they run on.

Think of it like this - there's a bee that only likes to live in it's own honeycomb, and will not be able to work if it lives somewhere else. You just trap the bee in a box that looks and feels exactly like it's honeycomb. That's containerization.

Containers are made using Images

works on my machine

Docker Images

Docker Images are like templates - a craftbook that has everything to make the craft. Or, in other words, it contains a set of instructions for creating a container.

But how do you make these images (to later make containers) ?

This is done using Dockerfiles.

All about Dockerfiles

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
Ok, let's make a Dockerfile together.

Now, we'll start with docker HANDS ON!

Quickly download docker on your device :

Now that you have it, let's write a simple flask application and containerize it!

Here's a very simple and minimal flask app
Image description

Now, even though this might be very basic, it actually needs a lot of things to run:

  • Python 3.9
  • Flask (running pip install flask)
  • exposure to port 5000

Some programs might only run on specific Operating systems - like Windows-only or Linux-only stuff.

All these problems are solved by writing a simple dockerfile, that sets up a docker image for us.
So you need to make a file called Dockerfile (exactly, without any file extension)

Here is a walkthrough:

  • use FROM to use python base image
  • use COPY to copy the file into the container
  • use RUN to pip install flask
  • use CMD to run "python" when container starts

Its as easy as that!!!

minor correction : the file should be named Dockerfile instead

Building the image and running container

Now, build to docker image using the docker build command and then run the image by using the docker run . command.

You can also use the --tag to give a name to the image and make it easier for yourself to run later

docker build --tag flask .
docker run --name flask -p 5000:5000 flask
Enter fullscreen mode Exit fullscreen mode

Here, --name is the name of the container to be run (which i'm naming flask), -p sets the port of the docker CONTAINER to your machine, so you can see your app on localhost. Finally, the flask at the name is the name of the image to be run.

More commands

That's pretty much it!!!
use the "docker ps" command to get a list of running containers,
"docker ps -a" to get list of ALL containers
"docker images" to get list of images

"docker --help" to get list of all commands

Mess around with the commands, they are self-explanatory

Read the official documentation here.

If you learnt something in this blog, make sure to ๐Ÿ’– it, and follow me if you REALLY liked it!

Discussion (61)

mtwn105 profile image
Amit Wani

Wish someone could have taught me like this when I was 5 ๐Ÿ˜ Awesome๐Ÿš€

dhravya profile image
Dhravya Author

thanks a lot!

mohamedtammam profile image
Mohamed Abdallah

Docker wasn't there when you were 5 ๐Ÿ˜‚

rahulkumarmalhotra profile image
Rahul Kumar

Thank you so much for this tutorial.

mgonzalo profile image
Gonzalo Muรฑoz

Dude!! I got to confess: today I won a battle against prejudice.
When I saw "16yr old" on yet another dev blog, I was about to nope outta here (I've had bad experiences before)
But something made me stay. I couldn't put my finger on it at first, but it turns out that you really have a knack for explaining things (not the same as writing about something). I loved the clean and concise style and even some figures like the one with the bee.
I'm almost twice your age, but today I learned from you.
Keep up the good work, and never stop growing!

dhruv194 profile image
Dhruv Mehta

Damn bro! You are just 16 years old but you explained what Docker really is in a way like you have been learning docker since you were born XD
Very well done. I am really very impressed.

just_moh_it profile image
Mohit Yadav

Haha, really!

marcomoscatelli profile image
Marco Moscatelli

I am learning this concept right now and this explanation was very helpful

dhravya profile image
Dhravya Author

thank you for the feedback!

njmsaikat profile image
Saikat Roy

Wow Really Great Explained. when I first started faced a lot of difficulties to just imagine those basic things.

dhravya profile image
Dhravya Author

I know, right! Same with me. I used to try to watch these tutorials which would be lengthy and still ended up confused with the basics

annetawamono profile image
Anneta Wamono

Your post makes me want to start messing around with Docker. Thank you for your very approachable introduction to Docker.

dontfixyourpc profile image
Richard Rhein

Awesome explanation, good idea to explain in simple words, so that everybody can understand this.

paimanrasoli profile image

Nice explanation ๐Ÿ˜

dhravya profile image
Dhravya Author

Thanks a lot!

devanica profile image

Finally someone said it, and in a way that I understand it. There are tutorials for everything but publishing APIs and other "little things" gave me a lot of headaches!

dhravya profile image
Dhravya Author

Thank you! Glad I could help

thegreytangent profile image
TheGreyTangent • Edited on

This is the most precise basic explanation about docker.

dhravya profile image
Dhravya Author

Thanks a lot! Glad you liked it

tqbit profile image

But it works on my machine

Then we'll ship your machine

Got me good. Noted.

just_moh_it profile image
Mohit Yadav

Awesome explanation, and congrats for this article's hotness ๐Ÿ˜ Well deserved ๐Ÿ˜ƒ

dhravya profile image
Dhravya Author

Thank you very much!

_leticiaberry profile image
Leticia Berry

Very clear explanation. Thank you!

diballesteros profile image
Diego (Relatable Code)

Really nice explanation!

pawanprateek16 profile image

Very useful and Helpful informative.

ckvignesh profile image

Hey this is an awesome article. Great way to put things in an easy-to-understand format.

mfurmaniuk profile image

Love the "explain to a 5 year old" memes

dhravya profile image
Dhravya Author

hahah yeah, it's not really for a 5 year old

svgatorapp profile image

Super helpful :D Awesome of you to share

devibhattaraii profile image

Oooh this explanation is amazing!

usmangq12 profile image

Thank you. This article has cleared a lot of my confusions related to Docker. I really appreciate it.

hiweus profile image
Andre Alves Leocadio

Nice explanation ๐Ÿ˜

jacksonkasi profile image
Jackson Kasi

wow! nice ๐Ÿค—

dhravya profile image
Dhravya Author

Thank you!

mirzafay profile image

I have no words to describe. this is the best and simple explanation of docker!
i was so confused about containers. thanks alot!!

chaocyu profile image

Awesome post. Do you think Docker is good for local development ? I'm definitely sold that for deployment it is awesome. For local dev, although it saves some environment settings hassles, everything we do now need to be through docker. so far I felt a bit overkill to use docker for local dev environment. appreciate your thoughts!

dhravya profile image
Dhravya Author

For local development, yeah, it's not ideal. But for stuff like keeping multiple background processes online, (like running an API on computer when it's on), is an ideal use-case for docker desktop because then you can have multiple stuff running in the background with the minimum memory usage and no hassle of setting it up to run automatically and stuff

bherbruck profile image

If you use vscode, check out devcontainers. They changed my life. I never develop on my host OS and ALWAYS in a devcontainers now.

dhravya profile image
Dhravya Author

Yes, I checked it out too. They are really good

photostockedit1 profile image


olukaisaac profile image
Oluka Isaac

This is awesome

bobbyiliev profile image
Bobby Iliev

Great post! well done! ๐Ÿ™Œ

For anyone interested to learn more, I could suggest this free eBook here:

GitHub logo bobbyiliev / introduction-to-docker-ebook

Free Introduction to Docker eBook

๐Ÿ’ก Introduction to Docker

This is an open-source introduction to Docker guide that will help you learn the basics of Docker and how to start using containers for your SysOps, DevOps, and Dev projects. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you will most likely have to use Docker at some point in your career.

The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Docker.

๐Ÿš€ Download

To download a copy of the ebook use one of the following links:

๐Ÿ“˜ Chapters

๐ŸŒŸ Sponsors

Thanks to these fantastic companies that made this book possible!

sixman9 profile image
Richard Joseph

You've made me sad, and I haven't read this yet (I will). Why? Because, for some unknown reason, I was thinking of writing something like this, on Docker, only last week, I was going to call mine "Explain Docker to me like I'm 5 years old", this is not a joke, I will get over it ๐Ÿ˜ญ

kkbava profile image
Krishna Kishore (KK)

Good introduction, but I dont agree with the title! A 5-year old wouldnt have learnt anything from this post - probably great for a developer with 1 year experience?
Wish you had written some lines explaining WHY a containerization is needed - what problems existed before!
Overall, this is a great short intro to getting started! Thanks!

dhravya profile image
Dhravya Author

Hi there! Thanks for your feedback. The title is just a metaphorical way of saying "in easy terms", and not for a real 5 year old. It's common to see such posts in DEV community