Dockerize your Koop app for deployment
Docker is a widely adopted technique for application containerization and deployment to cloud services. In this tutorial, we are going to talk about how to dockerize a Koop application. It is based on the great article Dockerizing a Node.js web app and tailored for a Koop app generated by Koop CLI (like this).
We assume the reader has some knowledge of Docker.
First of all, you need to create a
Dockerfile in the project root directory. It is as simple as
# Based on the latest Node.js LTS version FROM node:12 # Create app directory in docker WORKDIR /usr/src/app # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied # where available (npm@5+) COPY package*.json ./ RUN npm install # If you are building your code for production, run this instead of install # RUN npm ci --only=production # Copy app source code COPY . . # Expose the server port. This must be the same as the one in the config (config/default.json) EXPOSE 9000 # Start the Koop app CMD [ "node", "src/index.js" ]
To avoid copying the heavy
node_modules directory in the docker image, you can add a
.dockerignore file in the project root directory, with the following content:
Now the Koop app is ready to use with Docker.
You can build the docker image with the following command
docker build -t docker-koop .
and run it with
docker run -p 9000:9000 docker-koop
You should now have a Koop server running at
If you are interested in running Koop with Docker, you can take a look at our Koop Docker Example and use it as a template for your next app!