docker - Docker:在 Buildkit 中使用 SSH
问题描述
按照文档,我正在尝试将 SSH 密钥传递给我的容器。这是我原来的 Dockerfile
# syntax=docker/dockerfile:experimental
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.6
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh git clone git@github.com:USER/REPO.git
这有效
DOCKER_BUILDKIT=1 docker build --ssh default=~/github .
但是,如果我尝试使用 apt 安装任何东西:
# syntax=docker/dockerfile:experimental
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.6
RUN apt update
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh git clone git@github.com:USER/REPO.git
我收到以下错误:
[+] Building 1.8s (7/9)
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 306B 0.0s
=> resolve image config for docker.io/docker/dockerfile:experimental 1.1s
=> CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:de85b2f3a3e8a2f7fe48e8e84a65f6fdd5cd5183afa6412fff9caa6871649c44 0.0s
=> [internal] load metadata for docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.6 0.0s
=> CACHED [1/4] FROM docker.io/tiangolo/uvicorn-gunicorn-fastapi:python3.6 0.0s
=> ERROR [2/4] RUN apt update 0.4s
------
> [2/4] RUN apt update:
#7 0.352
#7 0.352 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
#7 0.352
#7 0.359 Reading package lists...
#7 0.375 E: Could not get lock /var/lib/apt/lists/lock - open (13: Permission denied)
#7 0.375 E: Unable to lock directory /var/lib/apt/lists/
------
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to build LLB: executor failed running [/bin/sh -c apt update]: runc did not terminate sucessfully
但是,如果禁用了 Buildkit,第二个 Dockerfile 确实可以工作。关于可能是什么问题的任何建议?
解决方案
我有这个完全相同的问题。对我来说,解决方案是升级 Docker。我遇到了这个问题19.03.11
,我的 Ubuntu 安装很快就解决了。20.10.1
(截至这篇文章的最新版本)为我工作。
更多信息:https ://github.com/moby/moby/issues/39106#issuecomment-752246367
编辑:不幸的是,当以非交互方式运行时(例如,作为基于 systemd 的 CI 代理),这不起作用build
- 至少对我而言。
推荐阅读
- ads - 使用 DFP 为小型企业提供叠加层和徽标的视频
- apache - cakephp css/js 未加载
- sql - 为什么即使第一个为真,也会检查多个 OR 条件?
- sql - 在 MSSQL 中使用附加的 max() 条件从数据库中检索每个组中的最后一条记录
- apache-spark - python spark在elasticsearch中写入时间戳
- javascript - 操作三个数组
- c++ - 基于模板成员存在的 C++ 成员重载
- python - 在 Google Colab 中运行 2 个 python 脚本
- apache-spark - 如何在 Spark SQL 中将多列分解为行
- python - 从 pd.Series.value_counts 输出中删除最后一行