简体   繁体   English

Install a python package using pip from private GitHub repo when building Docker image?

[英]Install a python package using pip from private GitHub repo when building Docker image?

################################################################################
# Ubuntu 22.10
FROM ubuntu:22.10
################################################################################
# Install packages
RUN apt-get update && apt-get install --yes --no-install-recommends \
  build-essential \
  gfortran \
  meson \
  pkg-config \
  sox \
  git \
  cmake \
  openssh-client \
  python3 \
  python3-pip \
  python3-numpy 
################################################################################
# Create a Jenkins user with proper host group id and user id
ARG UNAME=jenkins
# Get group and user ids from outside "docker build" command line
ARG GID=
ARG UID=
RUN groupadd --gid $GID $UNAME && \
    useradd --gid $GID --uid $UID --home-dir /home/$UNAME --create-home $UNAME
################################################################################
# Add github.com to the list of known ssh hosts for user Jenkins
USER $UNAME
RUN mkdir /home/$UNAME/.ssh/ && \
    touch /home/$UNAME/.ssh/known_hosts && \
    ssh-keyscan github.com >> /home/$UNAME/.ssh/known_hosts
################################################################################
# Install myproj from myrepos:
RUN pip3 install --upgrade --user git+ssh://git@github.com/myrepos/myproj@master
################################################################################

I've created the above Dockerfile used by Jenkins automation server.我已经创建了 Jenkins 自动化服务器使用的上述 Dockerfile。 The Dockerfile contains some fiddling with SSH keys to enable jenkins user to access my Git repositories. Dockerfile 包含一些对 SSH 密钥的摆弄,以使jenkins用户能够访问我的 Z0BCC70105AD279FEB665Z1 存储库F4F4。 This enabled jenkins to run meson build system commands (and meson needs access to GitHub).这使jenkins能够运行meson构建系统命令(并且meson需要访问 GitHub)。 All worked OK.一切正常。

But now I needed to install a package from my GitHub repo which I usually install like this:但现在我需要从我的 GitHub 存储库中安装 package,我通常这样安装:

pip3 install --upgrade --user git+ssh://git@github.com/myrepos/myproj@master

However, when docker is run, I get error on the last RUN line:但是,当 docker 运行时,我在最后一个 RUN 行出现错误:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

How would I access the repo from Dockerfile?如何从 Dockerfile 访问存储库?

Your github repo is added to known hosts, but what about your repo key?您的 github 存储库已添加到已知主机,但是您的存储库密钥呢? How will the image you build via this Dockerfile know what that is?您通过此 Dockerfile 构建的映像如何知道那是什么?

Hypothetically you could COPY the key into the image so it has access and can pull from the private repo, but this isn't secure.假设您可以将密钥COPY到映像中,以便它可以访问并可以从私有存储库中提取,但这并不安全。 You would additionally be adding more private credentials (from your github repo) to the image if you do this.如果您这样做,您还将向图像添加更多私有凭据(来自您的 github 存储库)。

I would clone the repo locally and COPY the required files in, or mount as a volume.我会在本地克隆 repo 并COPY所需的文件,或者作为卷安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pip 从私有 github repo 安装 package 与部署密钥 Z05B6053C41A2130AFD6BDA3B - pip install package from private github repo with deploy key in docker Pip 在谷歌云应用引擎中从私有 github repo 安装 package - Pip install package from private github repo in google cloud appengine 我如何使用jenkins从私人github存储库安装python软件包? - How do I install python package from private github repo using jenkins? 来自私人 github repo 的 pip install wheel 版本 - pip install wheel version from private github repo 是否可以使用 pip 从私有 GitHub 存储库安装包? - Is it possible to use pip to install a package from a private GitHub repository? 从PIP安装软件包时,使用专用存储库/服务器 - While installing package from PIP it using private repo/server pip 从私人仓库安装,但 PyPi 的要求仅安装私人仓库 package - pip install from private repo but requirements from PyPi only installs private package 使用PIP从Github安装Python包 - Installing Python Package from Github Using PIP 使用 docker build 安装 github 组织私有包 - Install github organization private package using docker build pip 从私有仓库安装一个包,但从代理后面的 PyPi 安装依赖 - pip install a package from a private repo but dependencies from PyPi behind a proxy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM