简体   繁体   English

在 python requirements.txt 中带有私有 github repo 的 DockerFile

[英]DockerFile with private github repo in python requirements.txt

I have a python project that I am writing a dockerfile for.我有一个 python 项目,我正在为其编写 dockerfile。 This project depends on another python project of mine that is hosted in a private github account of mine.这个项目依赖于我的另一个 python 项目,它托管在我的私人 github 帐户中。

How do I go about making the dockerfile properly load in the other project as a dependency (using my requirements.txt file)?如何使 dockerfile 作为依赖项正确加载到另一个项目中(使用我的 requirements.txt 文件)?

I tried copying my private ssh key into the:我尝试将我的私人 ssh 密钥复制到:

/root/.ssh

directory as part of the DockerFile, and including the clone url as part of the requirements.txt file, but this just feels wrong since my private key will be stored in one of the docker image layers.目录作为 DockerFile 的一部分,并将克隆 url 作为 requirements.txt 文件的一部分包含在内,但这感觉不对,因为我的私钥将存储在 docker 镜像层之一中。

Are there best practices for this?是否有最佳实践?

Generate a Personal access token .生成个人访问令牌

You should select a scope of this token to limit access to your personal project.您应该选择此令牌的范围以限制对您个人项目的访问。

You can pass a token to curl instead of user/password您可以将令牌传递给 curl 而不是用户/密码

curl -u <token>:x-oauth-basic

Since Docker API version 1.39+ you can use a different build mode to access your local SSH private key instead of copying it to the image.从 Docker API 版本 1.39+ 开始,您可以使用不同的构建模式来访问本地 SSH 私钥,而不是将其复制到映像。

See more here: https://stackoverflow.com/a/58883743/435093在此处查看更多信息: https : //stackoverflow.com/a/58883743/435093

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM