Hi,
I’m trying to bind local host directory with the voume inside container so i can use it for hot code reloading, whenevr there is change in code the changes gets reflect immediately on container. I have build and image and when i run the image I can see the permission are set for the user which i created, but when i run it with docker-compose up command and exec in container I can see the files are been created for root user.
my dockerfile is like:
FROM node:16-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package.json .
USER node
RUN npm config set unsafe-perm true
RUN npm install
COPY --chown=node:node . .
RUN npm run build
CMD npm run dev
and my docker-compose file is:
version: ‘3.3’
networks:
node-app-network:
driver: bridge
services:
node_app:
container_name: nodeapp
build:
context: .
dockerfile: Dockerfile
env_file:
- .env
environment:
DB_HOST: ${DB_HOST}
DB_DATABASE: ${DB_DATABASE}
DB_USERNAME: ${DB_USERNAME}
DB_PASSWORD: ${DB_PASSWORD}
DB_PORT: ${DB_PORT}
NODE_ENV: ${NODE_ENV}
APPLICATIONS_DB_HOST: ${APPLICATIONS_DB_HOST}
APPLICATIONS_DB_DATABASE: ${APPLICATIONS_DB_DATABASE}
APPLICATIONS_DB_USERNAME: ${APPLICATIONS_DB_USERNAME}
APPLICATIONS_DB_PASSWORD: ${APPLICATIONS_DB_PASSWORD}
APPLICATIONS_DB_PORT: ${APPLICATIONS_DB_PORT}
SCRAPER_DB_HOST: ${SCRAPER_DB_HOST}
SCRAPER_DB_DATABASE: ${SCRAPER_DB_DATABASE}
SCRAPER_DB_USERNAME: ${SCRAPER_DB_USERNAME}
SCRAPER_DB_PASSWORD: ${SCRAPER_DB_PASSWORD}
SCRAPER_DB_PORT: ${SCRAPER_DB_PORT}
ports:
- “${PORT}:3001”
expose:
- 3001
volumes:
- .:/home/node/app
- node_modules:/home/node/app/node_modules
networks:
- node-app-network
command: npm run dev
volumes:
node_modules: