我在docker文件中指定了一个git clone
命令,如下所示。
RUN git clone https://github.com/zhaoyi0113/test.git
但是在构建docker镜像时,我得到了这个错误:
Cloning into 'test'...
fatal: could not read Username for 'https://github.com': No such device or address
我想知道为什么它不能工作。我可以在我的主机上运行这个命令。如果我把它列在docker文件上会有什么不同吗?
发布于 2018-09-13 07:05:57
您可以将凭据作为参数传递给容器。这应该是可行的
FROM alpine:3.8
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh
ARG username
ARG password
RUN git clone https://${username}:${password}@github.com/username/repository.git
ENTRYPOINT ["sleep 10"]
但是,如果您想要分发该映像,则可能不安全
然后构建
docker build \
--no-cache \
-t git-app:latest \
--build-arg username=user \
--build-arg password=qwerty \
.
发布于 2018-08-15 08:48:55
我知道这个问题出了什么问题。问题是因为我克隆的存储库是私有存储库,这意味着它需要凭据才能连接到github。通过将凭据传递到容器来修复它。
https://stackoverflow.com/questions/51851123
复制相似问题