Dockerizing a Node.js web application
In this article, I would like to document how I dockerize my portfolio web site, which is a Node.js application.

Search for a command to run...
In this article, I would like to document how I dockerize my portfolio web site, which is a Node.js application.

No comments yet. Be the first to comment.
GitHub Actions can be used as a CI tool for building, testing and deploying our code. With the aid of Synk, it can also automate the process of checking vulnerabilities. Introduction Snyk is a developer security platform for securing code, dependen...
In this article, we'll write a JUnit Test configured with Environment Variables using junit-pioneer library. First of all, we need to add the junit-pioneer library and maven-surefire-plugin to the Maven pom.xml. <project> <properties> <p...
Problem The problem occurs when using the Python requests library, the chardet library is not installed. /Users/adacheng/Library/Python/3.9/lib/python/site-packages/requests/__init__.py:86: RequestsDependencyWarning: Unable to find acceptable charact...

Apache Kafka is an open-source distributed event streaming platform for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications. Introduction This article aims to provide basic hands-on instructions ...

Problem When AWS STS module is included in a Spring Boot Application, exception complaining region not set is thrown. Maven pom.xml <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>sts</artifactId> </dependency> Error M...

Installation Follow the instruction in this article to install Trivy. Scan To scan the docker image: Build the image. docker build . -t hello-world Scan the image. trivy scan hello-world

Firstly, create Dockerfile for the Node.js application.
FROM node:14.18.2-alpine3.14
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY ./ ./
RUN npm ci
CMD ["npm", "run", "start"]
Since I've used node-sass package for enabling SASS in my application and the package supports limited Node.js version, I need to find the right node.js docker image at docker hub.

At docker hub, search for the right image in the Tags tab. Once the desired image is found, put it on the first line (i.e. the FROM layer) of the Dockerfile.

Secondly, create .dockerignore file to exclude files and directories from the docker image.
node_modules
*.log
Thirdly, build the Node.js application.
yarn build
Fourthly, build the docker image.
*Make sure Docker Engine is running in your development environment.
docker build -f Dockerfile -t portfolio-website .
docker run --name portfolio-website -it -p 5001:3000 portfolio-website
http://localhost:5001/ in a web browser.