---
title: Run a NodeJS Container App
slug: docs-containers/run-a-nodejs-container-app
description: How to run a NodeJS Container App on Back4app platform using a Dockerfile.
docTags: 
createdAt: 2023-02-08T14:20:43.000Z
---



::embed[]{url="https://www.youtube.com/watch?v=PicWPUzpZwA"}

Docker is a technology that allows you to package and run applications in containers. Back4App Containers are based on Docker technology and use Docker containers to isolate and run the applications. This provides several benefits, such as improved performance, enhanced security, and simplified deployment and scaling.

&#x20;To run a Node.js application on Back4app Containers, you need to create a Dockerfile that contains the instructions for building the Docker image. Here is a step-by-step guide on how to create a Dockerfile for a Node.js application.

:::hint{type="info"}
At anytime if you want to check a sample working NodeJS project on Back4app containers go to : [[https://github.com/templates-back4app/containers-node-express-sample](https://github.com/templates-back4app/containers-node-express-sample)](https://github.com/templates-back4app/containers-python-flask-sample)
:::

1- Choose a Base Image: The first step is to choose a base image for your Dockerfile. For Node.js applications, you can use an official Node.js image from the Docker Hub. You can choose a specific version of Node.js by specifying the tag in the image name. For example, to use Node.js version 14, the first line of your Dockerfile would be:

```dockerfile
FROM node:14
```

2- Set the Working Directory: Next, you need to set the working directory in the container where the application files will be located. You can use the `WORKDIR` instruction to set the working directory. For example:

```dockerfile
WORKDIR /app
```

3- Copy the Application Files: Now, you need to copy the application files into the working directory. You can use the `COPY` instruction to copy the files. For example:

```dockerfile
COPY . /app
```

4- Install Dependencies: In order to run the application, you need to install its dependencies. You can use the `npm install` command to install the dependencies. You can run the command in the Dockerfile using the `RUN` instruction. For example:

```dockerfile
RUN npm install
```

5- Set Environment Variables: If your application requires environment variables to be set, you can set them in the Dockerfile using the `ENV` instruction. For example:

```dockerfile
ENV PORT 8080
```

6- Expose the Port: To make your application accessible from outside the container, you need to expose the port on which it is listening. You can use the `EXPOSE` instruction to expose the port. For example:

```dockerfile
EXPOSE 8080
```

7- Define the Entry Point: The last step is to define the entry point for the container, which is the command that will be run when the container starts. For Node.js applications, you can use the `npm start` command as the entry point. For example:



```dockerfile
CMD ["npm", "start"]
```

Here is the complete Dockerfile for a simple Node.js application:

:::CodeblockTabs
```dockerfile
bashCopy code
FROM node:14
WORKDIR /app
COPY . /app
RUN npm install
ENV PORT 8080
EXPOSE 8080
CMD ["npm", "start"]
```

```dockerfile
#Sample Dockerfile for NodeJS Apps

FROM node:16

ENV NODE_ENV=production

WORKDIR /app

COPY ["package.json", "package-lock.json*", "./"]

RUN npm install --production

COPY . .

EXPOSE 8080

CMD [ "node", "index.js" ]
```
:::



Once you have created the Dockerfile, you need to paste it on your projet root or on any folder(just specify that on the Root parameter on App Settings) and create or re-deploy your Application. Back4app will create a Docker image based on this file and a Container using this image. This way, you can run your Node.js application in a Bak4app Containers.





