Docker for dummies… 🐳 🧠💡
🚀 Dockerize a hello-world node app with me, in 15 mins.
This is the first article of the “Docker for dummies… 🐳 🧠💡” series, in which I will explain docker’s what, why, and how in simpler steps. By end of reading this series, you would be able to know what docker is, why you need to dockerize your projects and how you can do that!
Each article is structured in a stand-alone intuitive way, so that you can read just this article only, to find what you might be looking for.

Understanding the problemo 🚩 first!
You read it right! I call it problemo not problem 😁…
Let’s take a step back to understand why we even need docker and what is the problem that it is trying to solve. Say you are a web developer and have built an app, that you have to
a. Test on your PC at your home.
b. Share with a colleague, that he has to run on his own PC.
c. Deploy on the production server, where quite a few other apps are already up and running.
Well… you better know, before being able to run your node app anywhere, you have to set up the Environment on the host first.
For that you have to make sure, you have the right packages and node version, you need, to smoothly run your app on a host. But here is a potential issue…

The development environment of your PC is different from the one you got at home. Say it has node v12 and your app needs v14. You can’t upgrade to v14, you got other projects on your home PC using v12… 😕
Your colleague’s PC has no capacity to install new packages your app needs..😕
The production server has other apps running on it, and your app’s dependencies are clashing with other apps running there too…😕
I think… by now, you got the problem. The development environment tends to vary greatly from system to system, and this apparently easy task of shipping your build apps to other systems is not that easy after all! We don't want a whole mess of uninstallation and installation every time we have to deploy our app anywhere!
No worries…. Docker🐳 to the rescue!🦸
What is Docker🐳 ?
Now is a good time to ask, what is docker?
It will help you solve the problem of varying development environments for app shipping and deployment.

Docker🐳 is a technology to create and manage containers.
Wait… what?
A container is nothing but a software unit, i.e. your node app's code, and its dependencies. Containers allow execution of your app in isolation, anywhere in the world, by anyone, without you worrying about the environment set-up….. Ain’t that just awesome!🤩
How does Docker🐳 do the magic?
Docker🐳 is a container management framework, it allows you to create, share and manage images and containers. But what are containers and images in the first place and how do they allow us to solve the problem of varying development environments?

Images 🖼️
Of course, images are not framed pictures 😁… Just remember three things:
a. Images are blueprints/templates for a container.
b. It contains your code and its dependencies.
c. You can run a container on top of an image, to run your application.
Containers 📦
You see docker’s logo in the image up there. It has a whale carrying “Containers” across the sea from one country to another. That is exactly what a container is….
It creates an isolated environment for running your application at the host machine using information (code + dependencies) from the image. It’s a running unit of your application.
With containers and images, you won’t have to worry about installing and uninstalling dependencies on a host, before running your application there. You simply create an image (snapshot of your running app i.e. code+depedencies) and share it with person X. Mr. X can now simply spin up a container on top of that image and can run your app, without having to worry about anything!🧡

Docker 🐳 SetUp ⚒️
Enough with the theory, we will set up docker on our systems and dockerize a simple hello-world node app to see it in action, and to understand it better.
If you are on mac… it is pretty straightforward to set docker up. You just need to go to download the Docker desktop from its official site, install it, and start it. If you see a cute little whale icon at top of your toolbar and click on it says it’s running…. you are all set!

For a detailed setup walkthrough, you can refer to the following resources:
☑️ Windows Installation 🏠
☑️ Linux Installation 🐧
☑ ️MacOS Installation 🍎
🚀 ️Let’s Dockerize!
To dockerize an app, you need to follow the following simple steps.
- Write an image
- Build the image
- Run container based on build image
- Share the image with anyone you want to show your app.
For following these steps we will dockerize a dummy hello-world node application. You don’t need to know node or JS to follow along, just focus on the dockerization.
Dummy Hello-World Node app
This dummy node app comprises of following files. The main NodeApp folder, with server.js and package.json files in it.
-- NodeApp
| server.js | package.jsonServer.js is a simple hello world app, that prints a message, when you visit localhost:3000, as the app is listening on that port.


