- Karan Pratap Singh
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.
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.
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!