- Docker is installed on the host
- A basic understanding of Node.js and
Create a project folder
Create a project folder of your choice. All the following files will be created under this folder.
This configuration assumes that there is a script called
build in your
package.json and it builds to a folder called
build with an entrypoint of
index.js. You may want to change these values.
FROM node:14-alpine # Or your preferred version and flavor of node WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . RUN npm run build FROM node:14-alpine # Or your preferred version and flavor of node WORKDIR /usr/src/app COPY package*.json ./ RUN npm ci --only=production COPY --from=0 /usr/src/app/build ./build RUN npm install -g pm2 CMD ["pm2-runtime", "build/index.js"]
version: "3.1" services: timelapse01: image: yourimagename user: "1000:1000" # Optional, but helps with file permissions. Use your uid and gid from the host
Build your image
In the terminal, run the following command on the project folder
docker build -t yourimagename .
yourimagename needs to be the same name as in your docker-compose.yml
Run your container
To start your container using the image you’ve just built, run the following terminal command in your project folder.
docker-compose up -d
Stop your container
In order to stop the container, run the following terminal command in your project folder.
Alternatively, run the following command to remove all the volumes associated with the container as well.
docker-compose down -v