Add Docker to your NodeJS workflow with 4 simple steps
--
Learn how to add Docker to almost any Node project with simple boiler plate code.
What is Docker and why should you use it?
Docker is a platform as a service which allows you to isolate an entire operating system via Linux containers. The files we create below are instructions for how Docker should build the Linux container. Dockerizing (is that a word?) your application should be the first step in your workflow as it provides a good base for your development and production environments. Onboarding new members to the project is easy too, just provide them the respective Dockerfile
and they’re good to go. Docker can become extremely complicated and you can add a lot of configuration to your application with Docker alone.
You will definitely benefit from spending time researching complex features of Docker!
Add Docker to your NodeJS apps in 4 steps
I don’t explain what the following code does, but docker has great documentation on it, https://docs.docker.com/engine/reference/builder/ .
All of the following config files will be at the root of your project. These files will work for probably 90% of your NodeJS applications, barring specific configuration.
If this is an application that will be shipped to production, create a separate Dockerfile.prod
that contains configuration for your production application. These config settings can be googled because there are many people who have used Docker in production. This helps separate dev vs prod configuration with ease.
- Create a
Dockerfile.dev
and add the following code
2. Create a docker-compose.yml
and add the following config