如何在我的Docker构建中包括本地软件包依赖关系?
我有一个turborepo monorepo,使用纱线工作区,看起来像这样
├istry-packages
toserm-common├isterm-common├-上级
服务
││││IT服务/auth
/auth依赖套件/服务器common和使用纱线工作区,就像这样,
"dependencies": {
"server-common": "*",
}
我想从服务/auth中构建一个docker映像,但是npm上的软件包/服务器common不是托管的,它是本地软件包。
因此,当构建以下Dockerfile时,
FROM node:16-alpine
WORKDIR /app
COPY package.json .
RUN yarn install --production
COPY . .
CMD ["npm", "start"]
它在纱线安装阶段失败,因为Docker是在本地软件包时尝试从NPM下载软件包的。
#9 8.441 error Received malformed response from registry for "server-common". The registry may be down.
有没有办法将此本地软件包包含在Docker Build中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是将您的本地软件包复制到容器中。
A solution would be to copy your local package into the container.
使用
纱线工作区
遇到类似问题。我最终只是构建了要在应用程序中使用的软件包,并重现了目录设置,以支持纱线工作空间使用的符号链接。这是我的设置:
项目root
package.json
dockerfile
如果想为
App1
构建图像,只需运行以下操作:docker build -t image -name -build -arg build_context = app1 -f dockerfile。
这应该有效。
nb。 为此,您希望您的脚本名称与软件包的名称匹配。
希望这会有所帮助。
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.