'Docker doesn't create custom node-red image
I'm new to docker and I've been trying to create a custom node-red image with custom flow for influxdb. Docker doesn't seem to use my dockerfile for the image creation.
This is my docker-compose:
node-red:
container_name: node-red
build: node-red
environment:
- TZ=Europe/Amsterdam
ports:
- "1880:1880"
volumes:
- node-red-data:/tmp/node-red_data
networks:
- node-red-net
Then, inside a folder called node-red I have this dockerfile:
FROM nodered/node-red AS base
COPY package.json .
RUN npm install --only=production
COPY nodered_flow.json /data/flows.json
CMD ["npm", "start"]
Both the package.json and the nodered_flow.json are in the same folder as the dockerfile. What am I doing wrong here?
Solution 1:[1]
In service.build, you need the path to the build context, in case the it is in the same directory you could use .. So this should work:
node-red:
container_name: node-red
build: .
environment:
- TZ=Europe/Amsterdam
ports:
- "1880:1880"
volumes:
- node-red-data:/tmp/node-red_data
networks:
- node-red-net
For more information check: https://docs.docker.com/compose/compose-file/compose-file-v3/#build
Solution 2:[2]
Your Dockerfile is wrong, it's putting your package.json in /usr/src/node-red and when you run npm install it will remove Node-RED.
It should look like this:
FROM nodered/node-red AS base
WORKDIR /data
COPY package.json /data
COPY nodered_flow.json /data/flows.json
RUN npm install --only=production
WORKDIR /usr/src/node-red
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | paltaa |
| Solution 2 | hardillb |
