DEV Community 👩‍💻👨‍💻

Cover image for Introduction to Dockerize series
Karan Pratap Singh
Karan Pratap Singh

Posted on • Updated on

Introduction to Dockerize series


Hey, welcome to the Dockerize series. Here, I will be discussing how to use docker with your applications during both development and production.

We'll also use techniques like Builder pattern, multi stage builds to optimize our production builds.

This will serve as in introduction to upcoming articles where we'll dockerize our React, Node, Go applications!

Docker...What and Why?


Docker is a software platform for building applications based on containers, which are small and lightweight execution environments.

It also helps to eliminate environment specific issues since you can replicate your production environment locally, which provides consistency across our teams.

Docker compose

docker compose

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the containers from your configuration.

Note: It's is not advised to use docker-compose to run your application in production environment. Use a container orchestration tools like Kubernetes, Openshift, AWS ECS etc.

Builder pattern

In Builder pattern we use a docker image (which usually contains the whole runtime) to create small build artifacts and then use those binaries/artifacts in another smaller image hence reducing size of our built image.

Let's take Node images for example, They're usually upwards of 850mb in general (some slim variants are bit smaller) as they contain the full runtime and other things which might not be useful to us in production. So we can use builder pattern to do the following:

  • Derive from a Node base image with the whole runtime/SDK
  • Copy your source code
  • Install dependencies
  • Produce build artifact/bundle (usually done with bundlers like webpack, parcel) etc
  • Use the built artifacts in a much smaller images like Alpine
  • Push the small image to a repository of your choice like AWS ECS, Dockerhub etc.

Multi stage builds

Multi-stage builds makes it easier to use the builder pattern without hassle of creating multiple files, copying builds to host system and other things we had to do to implement builder pattern. More info here


I go over builder pattern and multistage builds in this article

We're good to go! See you in the next part!

Top comments (6)

peteking profile image
Pete King

Looking forward to seeing more, keep it up.

For those who are more .net oriented, my blog series, API's from Dev to Production - Part 1 covers Docker also. Multi-stage builds, optimisation, CVE's and more.

karanpratapsingh profile image
Karan Pratap Singh Author

Thank you, React article is out!!

Also, Thanks for sharing the .net impl, I will check it out

codingsafari profile image
Nico Braun

Compose is not creating actual servics though. Despite the name service. Only a node swarm mode as manager can create actual services.

karanpratapsingh profile image
Karan Pratap Singh Author

Yes, right on! For microservices I use skaffold with minikube...thanks for the feedback, I'll fix it

outranker profile image

Why is docker-compose not recommended for production?

karanpratapsingh profile image
Karan Pratap Singh Author

Hi, Doing docker-compose up to update (properties of) running containers can result in some downtime, because of the re-creating of the containers. if you have prototype or simple usecase, compose might be okay

👋 Welcome new DEV members in our Welcome Thread

Say hello to the newest members of DEV.