---
title: "Cloud Ready Series: Dockerize Your JavaScript & Node.js Apps"
description: Is your app Cloud ready? Containerize your JavaScript/Node.js API with Docker create a consistent experience for everyone and everywhere your app runs.
image: https://www.bitovi.com/hubfs/Cloud%20Ready%20Series-%20Dockerize%20Your%20JavaScript%20%26%20Node.js%20Apps.png
---

- ![AI implementation](https://www.bitovi.com/hubfs/AIConsultingIcon.svg)
  
  [AI implementation](https://www.bitovi.com/services/ai-consulting)
- ![Systems engineering](https://www.bitovi.com/hubfs/icon%20-%20backend.svg)
  
  [Systems engineering](https://www.bitovi.com/services/systems-engineering-consulting)
- ![Project Management](https://www.bitovi.com/hubfs/icon%20-%20PM.svg)
  
  [Project Management](https://www.bitovi.com/services/agile-project-management-consulting)
- ![Product Design](https://www.bitovi.com/hubfs/icon%20-%20design.svg)
  
  [Product Design](https://www.bitovi.com/services/product-design-consulting)
- ![Frontend development](https://www.bitovi.com/hubfs/icon%20-%20frontend.svg)
  
  [Frontend development](https://www.bitovi.com/services/frontend-development-consulting)
- [View more
  
  →
  
  ](https://www.bitovi.com/digital-consulting-services)

We're Experts in...

- [JavaScript](https://www.bitovi.com/services/frontend/javascript-consulting)
- [AI training](https://www.bitovi.com/ai-training-for-software-engineers)
- [Angular](https://www.bitovi.com/services/frontend/angular-consulting)
- [Design systems](https://www.bitovi.com/services/axure-figma-migration)
- [React](https://www.bitovi.com/services/frontend/react-consulting)
- [Temporal](https://www.bitovi.com/services/backend/temporal-consulting)
- [React Native](https://www.bitovi.com/services/frontend/react-consulting/react-native)
- [Node.js](https://www.bitovi.com/services/backend/nodejs-consulting)

Showcase

![Yum! Brands](https://www.bitovi.com/hubfs/yum-showcase-link-1.png)

[View case study](https://www.bitovi.com/en/bitovi-yum-case-study)

More Projects

- [![Levi's](https://www.bitovi.com/hubfs/levis.svg)](https://www.bitovi.com/web-application-consulting-work/levis-ecommerce-responsive-redesign)
- [![Christie's International Real Estate](https://www.bitovi.com/hubfs/christies.svg)](https://design.bitovi.com/christies)
- [![BAFS](https://www.bitovi.com/hubfs/bafs.svg)](https://www.bitovi.com/ux-design-consulting/ux-case-studies/bafs-ppp)
- [View more
  
  →
  
  ](https://www.bitovi.com/our-software-consulting-work)

Open Source Tools

We build powerful tools and open source them to support the community.

[See what we've built →](https://www.bitovi.com/open-source)

- [![Blog](https://www.bitovi.com/hubfs/icon%20-%20blog.svg)
  
  BlogWe post about delivering products and solving problems.
  
  ](https://www.bitovi.com/blog)
- [![Partnerships](https://www.bitovi.com/hubfs/Handshake-1.svg)
  
  PartnershipsLearn about Bitovi's technology partners
  
  ](https://www.bitovi.com/partnerships)
- [![Academy](https://www.bitovi.com/hubfs/icon%20-%20academy%20(4).svg)
  
  AcademyFree courses to build delivery skills
  
  ](https://www.bitovi.com/academy)
- [![Open source tools](https://www.bitovi.com/hubfs/icon%20-%20open%20source.svg)
  
  Open source toolsUse or contribute to our community
  
  ](https://www.bitovi.com/open-source)

Let's Connect

- [![Discord](https://www.bitovi.com/hubfs/DiscordLogo.svg)
  
  Discord
  
  ](https://discord.gg/J7ejFsZnJ4)
- [![LinkedIn](https://www.bitovi.com/hubfs/LinkedinLogo.svg)
  
  LinkedIn
  
  ](https://www.linkedin.com/company/bitovi/)
- [![GitHub](https://www.bitovi.com/hubfs/GithubLogo.svg)
  
  GitHub
  
  ](https://github.com/bitovi/)

![Eggbot](https://www.bitovi.com/hubfs/build_assets/bitovi-limbo-cms-react/338/js_client_assets/assets/eggbot-LTGhdSGL.png)

Name *

Work Email *

Phone

What's your project?

Send

### Contact Us

(312) 620-0386contact@bitovi.com

[ DevOps ](https://www.bitovi.com/blog/topic/devops) |  July 29, 2022

# Cloud Ready Series: Dockerize Your JavaScript & Node.js Apps

 Is your app Cloud ready? Containerize your JavaScript/Node.js API with Docker create a consistent experience for everyone and everywhere your app runs.

![Connor Graham](https://app.hubspot.com/settings/avatar/19f570d0095455dae4ba023d96feaca9)

 Connor Graham

Share:

[![Twitter](https://www.bitovi.com/hubfs/limbo-generated/_astro/twitter-white.os3xLc3C_Z2nW4or.svg) ](https://twitter.com/intent/tweet?text=) [![Reddit](https://www.bitovi.com/hubfs/limbo-generated/imgs/icons/reddit.png) ](http://reddit.com/submit?url=)

[Docker](https://www.docker.com/) is a great way to accelerate new developer onboarding and reduce overall operational complexity in production by creating a consistent experience for everyone and everywhere an app needs to run.

Containerizing your JavaScript/Node API with Docker to create a cloud-ready application is accomplished by:

1. Writing a `Dockerfile` — a file that defines running instructions on how to build your application.
2. Creating a `docker-compose.yml` — a file that defines how to run multiple docker containers and set environment variables. You can use Docker without [Docker Compose](https://docs.docker.com/compose/), but it is far easier to build and run containers with Compose.

If you haven’t already, go ahead and [install docker](https://docs.docker.com/get-docker/). It’s the last cli tool you’ll ever need.

## Create Your JavaScript App

For this example, you’re going to create a two-file app. Although this app is only two JavaScript files, this pattern will work for containerizing applications for any programming language of any size! Both of these files exist in the same directory:

```
├── index.js
└── pacakge.json
```

### index.js

```
const express = require('express')
const app = express()
const port = process.env.PORT || 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
```

### package.json

```
{
  "name": "bitovi-blog-app",
  "version": "1.0.0",
  "scripts": {
"start": "node index.js"
  },
  "dependencies": {
"express": "^4.17.1"
  }
}
```

If you have a compatible version of node and npm installed, you can run this locally with `npm install` then `npm run start`, but if not, that’s okay because Docker will handle that for you!

## Writing a `Dockerfile`

Now you’re going to add a `Dockerfile` to your root directory. A `Dockerfile` contains a set of instructions on what dependencies, files, config, and packages we need to run an app. 

```
├── Dockerfile
├── index.js
└── pacakge.json
```

### Dockerfile

```
# Use node version 15
FROM node:15

# Set an environment variable PORT with a default value of 8000
ARG PORT=8000
ENV PORT=$PORT

# Copy everything (index.js and package.json) from local working dir in to the docker image
COPY . .

# Run npm install within the image to download node dependencies
RUN npm install

# On startup, run npm start
CMD npm run start
```

This is a simple `Dockerfile` that will build and run the app on port 8000. You can optimize this process by leveraging [multi-stage builds](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#use-multi-stage-builds) among other [neat Docker tricks](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/), but this file is sufficient for demonstrating basic Docker capabilities.

## Creating a `docker-compose.yml`

Without Docker Compose, you could build and run your docker container with `docker build -t my-node-app . && docker run my-node-app -p 9000:9000 -e PORT=9000`. Instead, you’re going to introduce a `.env` and `docker-compose.yml` file to codify these in to a simple `docker-compose up`.

Add `.env` and `docker-compose.yml` to your directory:

```
├── .env
├── Dockerfile
├── docker-compose.yml
├── index.js
└── package.json
```

### .env

This file defines environment variables that will be automatically read by `docker-compose.yml`. In this case, it will inject `MY_PORT` wherever it is referenced.

```
MY_PORT=9000
```

### docker-compose.yml

```
# docker compose api version - do not edit
version: "3.8"

# A list of containers we want to run. We're just running 1 here
services:
  # Our service is called "my-app"
  my-app:
# "my-app" is a docker image that will be built on demand
build:
  # The `Dockerfile` exists in the same directory
  context: .
# Will create a Docker image called "my-node-app"
image: my-node-app
# Will expose the running container on localhost:9000 regardless of what port the app is actually listening on (controlled by MY_PORT env var).
ports:
  - "9000:${MY_PORT}"
# Pass in env var PORT to the running container
environment:
  PORT: ${MY_PORT}
```

## Testing

Now that your app is built and Dockerized, it’s time to test! Go ahead and run `docker-compose up`, then open your browser to [http://localhost:9000](http://localhost:9000).

```
$ docker-compose up
Creating network "blog_default" with the default driver
Creating blog_my-app_1 ... done
Attaching to blog_my-app_1
my-app_1  | 
my-app_1  | > bitovi-blog-app@1.0.0 start
my-app_1  | > node index.js
my-app_1  | 
my-app_1  | Example app listening at http://localhost:9000
```

```
$ curl localhost:9000
Hello World!
```

You can stop your container with `ctrl+c` or `docker-compose down` in another tab and rebuild your container after making code changes with `docker-compose build`. Cool!

## Hungry for More?

This blog post has been a condensed version of a [free Learn Docker course](https://www.bitovi.com/academy/learn-docker.html). Check it out if you want to learn more about what is happening behind the scenes or to optimize your containers for both local development and production deployments.

### Need Help?

Bitovi has consultants that can help. Drop into [Bitovi's Community Discord](https://discord.gg/J7ejFsZnJ4), and talk to us in the `#devops` channel!

Need[ DevOps](https://www.bitovi.com/blog/the-complete-guide-to-devops) Consulting Services? Head over to [DevOps Consulting - Bitovi ](https://www.bitovi.com/devops-consulting), and book a free consultation.

 Previous Post

![](https://www.bitovi.com/hs-fs/hubfs/project%20lifecycle.png?height=117&name=project%20lifecycle.png) [ Project Management Series: What is the Project Lifecycle? ](https://www.bitovi.com/blog/project-management-series-project-lifecycle)

  

 Next Post

![Bitovi ESLint Config: Handpicked Rules to Improve Your Code](https://www.bitovi.com/hs-fs/hubfs/Bitovi%20ESLint%20Config-%20Handpicked%20Rules%20to%20Improve%20Your%20Code.png?height=117&name=Bitovi%20ESLint%20Config-%20Handpicked%20Rules%20to%20Improve%20Your%20Code.png) [ Bitovi ESLint Config: Handpicked Rules to Improve Your Code ](https://www.bitovi.com/blog/bitovi-eslint-config-handpicked-rules-to-improve-your-code)

```json
{
  "@context" : "http://schema.org",
  "@type" : "Organization",
  "address" : {
    "@type" : "PostalAddress",
    "addressCountry" : "United States",
    "addressLocality" : "Libertyville",
    "addressRegion" : "IL",
    "postalCode" : "60048",
    "streetAddress" : "1134 Pine Tree Lane "
  },
  "alternateName" : "Bitovi",
  "areaServed" : {
    "@type" : "GeoCircle",
    "geoMidpoint" : {
      "@type" : "GeoCoordinates",
      "latitude" : "41.8781",
      "longitude" : "87.6298"
    },
    "geoRadius" : "5000 km"
  },
  "description" : "Bitovi is a UX, UI design and front-end JavaScript development consulting company",
  "email" : "contact@bitovi.com",
  "image" : "https://www.bitovi.com/hubfs/bitovi-logo-x2.png",
  "logo" : "https://www.bitovi.com/hubfs/bitovi-logo-23-1.svg",
  "mainEntityOfPage" : {
    "@id" : "https://www.bitovi.com/blog/cloud-ready-series-dockerize-javascript-and-node-apps",
    "@type" : "WebPage",
    "description" : "Is your app Cloud ready? Containerize your JavaScript/Node.js API with Docker create a consistent experience for everyone and everywhere your app runs. "
  },
  "naics" : "541511",
  "name" : "Bitovi Web App Consulting",
  "sameAs" : [ "https://www.facebook.com/BitoviLLC/", "https://twitter.com/bitovi", "https://www.linkedin.com/company/bitovi" ],
  "telephone" : "312-620-0386",
  "url" : "http://bitovi.com"
}
```

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Connor Graham"
  },
  "dateModified" : "October 2, 2023, 5:40:21 PM",
  "datePublished" : "2022-07-29 13:00:00",
  "description" : "Is your app Cloud ready? Containerize your JavaScript/Node.js API with Docker create a consistent experience for everyone and everywhere your app runs. ",
  "headline" : "Cloud Ready Series: Dockerize Your JavaScript &amp; Node.js Apps",
  "image" : {
    "@type" : "ImageObject",
    "url" : "https://www.bitovi.com/hubfs/Cloud%20Ready%20Series-%20Dockerize%20Your%20JavaScript%20&%20Node.js%20Apps.png"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.bitovi.com/hubfs/bitovi-logo-23-1.svg"
    },
    "name" : "Bitovi"
  }
}
```