【问题标题】:Private node module pull inside docker私有节点模块拉入 docker
【发布时间】:2020-07-02 02:21:21
【问题描述】:

我有一个 node_module 的私有存储库,我通过将它包含在 package.json 中来安装它

ssh://git@github.com/iamsaquib/<pivate-repo>.git

当我在 docker 镜像中复制所有服务器文件并尝试执行 npm install 时,它无法安装软件包并抛出我没有适当的访问权限。我想我必须通过在 Dockerfile 中复制我的 id_rsa.pub 并将其添加为授权密钥来进行授权,这样做的正确方法是什么?

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"]

【问题讨论】:

  • 挂载本地ssh密钥-v ~/.ssh:/home/node/.ssh,也可能是~/.gitconfig:/home/node/.gitconfig
  • 我在某处看到它说要添加 id_rsa a.k.a 私钥,这不是正确的方法吗?我还需要将 id_rsa.pub 添加到授权密钥吗?

标签: node.js docker ssh


【解决方案1】:

您需要挂载 SSH 私钥 (/home/yourname/.ssh/id_rsa)。

您应该避免将私钥放在 Docker 映像中。一种解决方法可能是multi-stage image(安全性可能仍有争议)。

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"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 2018-10-26
    • 2014-07-20
    • 2020-02-26
    • 2022-08-21
    • 1970-01-01
    • 2014-11-27
    相关资源
    最近更新 更多