[英]Private node module pull inside docker
I have a private repository of a node_module which I install by including it in package.json我有一个 node_module 的私有存储库,我通过将它包含在 package.json 中来安装它
ssh://git@github.com/iamsaquib/<pivate-repo>.git
When I am copying all server files inside docker image and try to do a npm install it is unable to install the package and throws I don't have proper access rights.当我复制 docker 映像中的所有服务器文件并尝试执行 npm 安装时,它无法安装 package 并抛出我没有正确的访问权限。 I think I have to authorize by copying my id_rsa.pub inside Dockerfile and add it as authorized key, what is the correct way to do this?
我想我必须通过在 Dockerfile 中复制我的 id_rsa.pub 并将其添加为授权密钥来进行授权,这样做的正确方法是什么?
Dockerfile Dockerfile
FROM node:12-slim
ENV NODE_ENV=development
WORKDIR /app
USER root
COPY . .
RUN ./install.sh
RUN ./build.sh
EXPOSE 8000
CMD ["./run.sh"]
You need to mount SSH private key ( /home/yourname/.ssh/id_rsa
).您需要挂载 SSH 私钥(
/home/yourname/.ssh/id_rsa
)。
You should avoid putting private key in Docker images.您应该避免将私钥放在 Docker 图像中。 One work around could be multi-stage image (security might still be debatable).
一种解决方法可能是多阶段图像(安全性可能仍有争议)。
FROM node:12-slim as installer
ENV NODE_ENV=development
WORKDIR /app
USER root
COPY /home/yourname/.ssh /home/root/.ssh
COPY /home/yourname/.gitconfig /home/root/.gitconfig
COPY . .
RUN ./install.sh
RUN ./build.sh
RUN rm -rf /home/root/.ssh
RUN rm -rf /home/root/.gitconfig
# Final image
FROM node:12-slim
WORKDIR /app
ENV NODE_ENV=development
USER root
COPY --from=installer /app .
EXPOSE 8000
CMD ["./run.sh"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.