Reputation: 2978
I have a file structure like this:
/root-app
/api
/dashboard
package.json
yarn.lock
Dockerfile
docker-compose.yml
/root-app/docker-compose.yml
dashboard:
build: ./dashboard
command: yarn dev
volumes:
- ./dashboard:/usr/src/app
- /usr/src/app/node_modules
/root-app/dashboard/Dockerfile
FROM node
WORKDIR /usr/src/app
ADD package.json yarn.lock ./
RUN yarn install
COPY . .
When I run docker-compose up --build
folder node_modules
in /roor-app/dashboard
it's created but it's empty. Why? I should have my node_modules
for local development.
UPDATE 1
When I using absolute paths rather than relative paths
dashboard:
build: ./dashboard
command: yarn dev
volumes:
- ./dashboard:/usr/src/app
- ./dashboard/node_modules:/usr/src/app/node_modules
I get this error:
dashboard | yarn run v1.3.2
dashboard | $ webpack-dev-server --mode development
dashboard | /bin/sh: 1: webpack-dev-server: not found
dashboard | error Command failed with exit code 127.
UPDATE 2
My new /dashboard/Dockerfile
FROM node
WORKDIR /usr/src/app
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
and removed - ./hms-dashboard/node_modules:/usr/src/app/node_modules
from docker-compose.yml
, error from update-1 still here.
Upvotes: 1
Views: 1098
Reputation: 11
You could try installing on build currently running into an issue with exit code 0, but the node_modules will install.
I had an issue where the devDependencies
where not installing with yarn.
FROM node
ARG environment=development
RUN mkdir /client
WORKDIR /client
COPY . /client
EXPOSE 8080
RUN npm --version
RUN npm install yarn
CMD if ["$environment" = "development"]; then yarn install --production=false; else yarn install; fi
RUN echo $environment
CMD if [ "$environment" = "development" ] ; then yarn build && yarn start; else yarn build; fi
Upvotes: 1
Reputation: 2467
In your /root-app/dashboard/Dockerfile
remove copy command as you are already binding the same directory using volume.
Also use COPY instead of ADD command in Dockerfile.
COPY package.json ./
COPY yarn.lock ./
In docker-compose.yml remove the second volume
- ./dashboard/node_modules:/usr/src/app/node_modules
, As first directory (./dashboard) is already mounted (/usr/src/app/).
Let me see your output after these updates.
Upvotes: 0