I have a turborepo monorepo, using yarn workspaces which looks like this
├── packages
│ ├── server-common
├── services
│ ├── auth
Services/auth is dependant on packages/server-common and using yarn workspaces, imports it like so
"dependencies": {
"server-common": "*",
}
I want to build a docker image out of services/auth, however packages/server-common is not hosted on npm, it is a local package.
Hence, when building the following dockerfile
FROM node:16-alpine
WORKDIR /app
COPY package.json .
RUN yarn install --production
COPY . .
CMD ["npm", "start"]
It fails on the yarn install stage, because docker is trying to download a package from npm, when it is a local package.
#9 8.441 error Received malformed response from registry for "server-common". The registry may be down.
Is there a way that this local package can be included in the docker build?
2
Answers
A solution would be to copy your local package into the container.
Ran into a similar issue using
yarn workspaces
. I ended up just building the package I want to use in my app and reproducing the directory setup to support symlinks used by yarn workspaces.This was my setup:
PROJECT ROOT
package.json
Dockerfile
If you want to build an image for
app1
, simply run this:docker build -t image-name --build-arg BUILD_CONTEXT=app1 -f Dockerfile .
This should work.
NB. For this to work, you want your script names to match up with the names of the packages.
Hope this helps.