yarn install inside docker image with yarn workspaces yarn install inside docker image with yarn workspaces docker docker

yarn install inside docker image with yarn workspaces


This code won't work outside of the docker vm, so it will refuse in the docker, too.

The problem is you have built a code, and copy the bundled code. The yarn workspaces is looking for a package.json that you don't have in the dist folder. The workspaces is just creating a link in a common node_modules folder to the other workspace that you are using. The source code is needed there. (BTW why don't you build code inside the docker vm? That way source code and dist would also be available.)


Here is my dockerfile. I use yarn workspaces and lerna, but without lerna should be similar. You want to build your shared libraries and then test the build works locally by running your code in your dist folder.

################################################################################ Step 1 : Builder imageFROM node:11 AS builderWORKDIR /usr/src/appENV NODE_ENV productionRUN npm i -g yarnRUN npm i -g lernaCOPY ./lerna.json .COPY ./package* ./COPY ./yarn* ./COPY ./.env .COPY ./packages/shared/ ./packages/sharedCOPY ./packages/api/ ./packages/api# Install dependencies and build whatever you have to build RUN yarn install --productionRUN lerna bootstrapRUN cd /usr/src/app/packages/shared && yarn buildRUN cd /usr/src/app/packages/api && yarn build################################################################################ Step 2 : Run imageFROM node:11LABEL maintainer="Richard T"LABEL version="1.0"LABEL description="This is our dist docker image"RUN npm i -g yarnRUN npm i -g lernaENV NODE_ENV productionENV NPM_CONFIG_LOGLEVEL errorARG PORT=3001ENV PORT $PORT WORKDIR /usr/src/appCOPY ./package* ./COPY ./lerna.json ./COPY ./.env ./COPY ./yarn* ./COPY --from=builder /usr/src/app/packages/shared ./packages/sharedCOPY ./packages/api/package* ./packages/api/COPY ./packages/api/.env* ./packages/api/COPY --from=builder /usr/src/app/packages/api ./packages/apiRUN yarn install CMD cd ./packages/api && yarn start-productionEXPOSE $PORT###############################################################################