2

I am trying build a good workflow to work with docker and nodejs

I think that I have a good base, but I can not get the package-lock.json generated inside my container to my source code even though I have a defined volume

this is my Dockerfile:

FROM node
WORKDIR /app

COPY ./package.json ./
RUN npm install
RUN npm install -g nodemon
COPY ./src ./src

EXPOSE 3000

CMD ["nodemon", "./src/index.js"]

and this is my docker-compose.yml:

version: '3'
services:
  web:
    build: ./app
    command: nodemon ./src/index.js
    ports:
      - '8080:3000'
    volumes:
      - ./app/src:/app/src
      - /app/node_modules/
    links:
      - mysql
  mysql:
    image: mysql:5.6
    environment:
      - MYSQL_DATABASE=dev
      - MYSQL_USER=dev
      - MYSQL_PASSWORD=dev
      - MYSQL_ROOT_PASSWORD=dev
    ports:
      - '3306:3306'

In order to commit the package-lock.json to my version control tool, everytime I install a new package through npm install inside my container and a package-lock.json is generated/updated, I wanna move on to my source code the generated package-lock.json file

Baklap4
  • 3,914
  • 2
  • 29
  • 56
ajvn
  • 21
  • 3
  • Does your `package.json` live inside the `./app` folder? This is where your docker context is at.. How does your repo look like in treeview? – Baklap4 Jan 02 '19 at 21:12
  • Yes, my Dockerfile is in the `./app` folder – ajvn Jan 02 '19 at 21:14
  • But where is your local `package.json` file? is it in `/project/app/package.json` or is it under `/project/src/package.json` or even within the root `/project/package.json` – Baklap4 Jan 02 '19 at 21:16
  • my local `package.json` is in my `./app` folder, my `Dockerfile` is in my `./app` folder and my `docker-compose.yml` is in the root – ajvn Jan 02 '19 at 21:20

1 Answers1

0

You need to add /app to volumes because package-lock.json will be generated in this directory, won't be?

Since this you could replace your volumes:

volumes:

    - ./app/src:/app/src

    - /app/node_modules/

on:

volumes:
    - ./app:/app

Also I would choose /var/app instead of /app.