使用 docker-compose 中的机密从 ssh 的 git repo 中拉取

问题描述

我正在尝试使用 docker-compose 创建构建设置,这需要从私有存储库中提取 npm 包。

我的设置如下:

// docker-compose.yml
version: "3.9"
services:
  node:
    build:
      context: .
    volumes:
      - ./:/home/node/app
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
      - /etc/hosts:/etc/hosts:ro
    ports:
      - 3000:3000
    environment:
      //- USER_UID=${USER_UID:-1000}
      //- USER_GID=${USER_GID:-1000}
    secrets:
      - user_private_ssh_key
      - user_public_ssh_key
      - ssh_config

secrets:
  user_private_ssh_key:
    file: ~/.ssh/id_rsa
  user_public_ssh_key:
    file: ~/.ssh/id_rsa.pub
  ssh_config:
    file: ~/.ssh/config
# DOCKERFILE
FROM node:14

RUN apt-get update && apt-get install -y openssh-client
RUN mkdir -p /home/node/.ssh
RUN ln -s /run/secrets/user_private_ssh_key /home/node/.ssh/id_rsa
RUN ln -s /run/secrets/user_public_ssh_key /home/node/.ssh/id_rsa.pub
RUN ln -s /run/secrets/ssh_config /home/node/.ssh/config
RUN chown -R node:node /home/node/.ssh
# RUN chmod 600 /home/node/.ssh/*
# RUN chmod 644 /home/node/.ssh/config
RUN ls -la /home/node/.ssh
USER node:node

workdir /home/node/app

copY . /home/node/app
# if the next line works,the following will as well
RUN ssh -v [email protected]
# RUN yarn install --verbose

CMD ["yarn","dev"]

我可以看到我的秘密正在被添加到容器中。他们的内容也是正确的。

不起作用的是,ssh_config 没有被 openssh-client 读取。因此,它连接到 git.example.com 上的包的错误端口 (22)。在这种情况下正确的端口将是例如3333.

// error message
OpenSSH_7.4p1 Debian-10+deb9u7,OpenSSL 1.0.2u  20 Dec 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
Pseudo-terminal will not be allocated because stdin is not a terminal.
debug1: Connecting to git.example.com [IP_ADDRESS] port 22.

我缺少什么配置才能使其正常工作?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)