Docker, What is it? A super simple explanation

If you are here, you might already googled and search for docker definition. Some articles and videos are explaining it too technical and it might very hard to understand especially for junior developer. Ok, I'll straight to the point, what and how docker is used:

Let's imagine, you are working with two different node projects, let's assume it is a two web-app. Call it AppOne and AppTwo. AppOne is a new projects that builts by you/your team that use current dev environtment and match to your env dev such a Node version.

Then, the AppTwo is an old code (legacy code), made by you/your team years-years ago and still use old Node version.

The Problem Arrives

Assume AppOne use node version 18+, and AppTwo use node version 12. You installed node version 18 on your machine. But you need to develop this app at the same time. Upgrading/downgrading your installed node can be difficult and creates a compatibility problem.

Docker fix this problem. If you are using docker, you don't need node that attached to your machine directly, you only need docker and install spesific image and create a new container.

*a stupid simplified docker diagram

By using docker, we eliminate huge compatibility problem to our dev environment. This is simplified, because in real app, we tend to have more than one dev env (node, database (postgres, mysql, mongo, etc)).

Docker Common Terms

In big picture, you need to know at least two terms: docker image, docker container. Docker image is like dev environment that you need like Node, PostgreSQL, MySQL, Mongo, etc. For example, for our case, we need two image which is node_12 and node_18 that's it. We can use it on our different usage called container.

Container is like a pack of your app to run. Web app that use node might only needs node image. But other app like webservice that write in javascript (node app) need multiple images, for example: node, postgres.

Of course we have a lot of docker terms, but that two is a minimum knowledge to start.

Can I Use My Current Dev Env With Docker

Yes. I did it with postgreSQL that already installed on my machine (out of docker) back then because I have web-service app and I have no time to setup new image for the database, so I use my existing. Just be aware about how to connect it to your host machine.

I Tried Docker But Why I Need To *PUSH* My App Every Code Changes?

You need something called docker volume to automatically sync your app and your docker. :) You need to map your current app directory with docker directory. There is a ton of tutorial out there that you can try.

End Of The Word

When should I use docker?
When you need it.

What is the pros and cons of using docker?
+ eliminate compatibility with dev environment
+ easier to swap and install on another machine (you can wrap your app as an image, and other machine just install it, no need install different dev environment)

- need time to learn (it shouldn't that hard for basic use, but still take times)
- resource hog (similar like VirtualMachine, please consider your spesification)

Things to consider
*by default, docker container will run your app automatically on start up, if you see a very huge usage on RAM and CPU on docker after boot, just deactivate the autostart. You need to start it manually when you need it.

*you can connect between two container or more, also with the host machine. But it can be tricky, you can search called docker networking and how to write it in docker compose. You might be trapped on this.

Post a Comment