Build a web application with Docker, Parse, and Next.js - Part 5: Next.js & Docker

May 31, 2017

This article is the fifth in the series whose goal is to create a Docker-based web application. In this article, we will add the Next.js application created in the previous article to our Docker configuration.

The first thing we will do is create the Dockerfile for the Next.js application.

Create a Dockerfile in the web-app folder and add the code below:

FROM node:6
 
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
 
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
 
# Bundle app source
COPY . /usr/src/app
 
RUN npm run build
 
 
EXPOSE 3000
CMD [ "npm","run", "start" ]

Next, we will modify the docker-compose.yml file to add our new service. After the existing services, add the following code:

web-app:
 build: ./web-app
 container_name: "web-app"
 ports: - "3000:3000"

Finally, we test that it works:

docker-compose up

We are done adding the Next application to our Docker configuration.

In the next article, which will be the last in the series, we will deploy this configuration on DigitalOcean.

Series navigation