繁体   English   中英

如何从github存储库构建docker镜像

[英]How to build docker image from github repository

在官方文档中,我们可以看到:

# docker build github.com/creack/docker-firefox

它对我来说很好用。 Dockerfile docker-firefox是一个存储库,在根目录中有Dockerfile
然后我想构建 redis 映像和确切版本 2.8.10 :

# docker build github.com/docker-library/redis/tree/99c172e82ed81af441e13dd48dda2729e19493bc/2.8.10
2014/11/05 16:20:32 Error trying to use git: exit status 128 (Initialized empty Git repository in /tmp/docker-build-git067001920/.git/
error: The requested URL returned error: 403 while accessing https://github.com/docker-library/redis/tree/99c172e82ed81af441e13dd48dda2729e19493bc/2.8.10/info/refs

fatal: HTTP request failed
)

我上面有错误。 从 github repos 构建 docker 镜像的正确格式是什么?

docker build url#ref:dir

Git URL 在它们的片段部分接受上下文配置,用冒号 : 分隔。 第一部分代表 Git 将检出的引用,这可以是分支、标签或提交 SHA。 第二部分表示存储库中的一个子目录,它将用作构建上下文。

例如,运行此命令以使用分支容器中名为 docker 的目录:

docker build https://github.com/docker/rootfs.git#container:docker

https://docs.docker.com/engine/reference/commandline/build/

您指定为 repo URL 的内容不是有效的 git 存储库。 当你尝试时你会得到错误

git clone github.com/docker-library/redis/tree/99c172e82ed81af441e13dd48dda2729e19493bc/2.8.10

此 repo 的有效 URL 是github.com/docker-library/redis 因此,您可能想尝试以下操作:

docker build github.com/docker-library/redis

但这也行不通。 为了从GitHub构建,码头工人需要Dockerfile在库的根,howerer,这种回购不提供这一个。 所以,我建议你只需要克隆这个 repo 并使用本地 Dockerfile 构建镜像。

可以使用以下示例设置 Centos 7 容器来测试 ORC 文件格式。 确保转义#符号:

$ docker build https://github.com/apache/orc.git\\#:docker/centos7 -t orc-centos7

docker run -p 3000:3000 -e github =' https://github.com/URL'-it IMAGE_NAME

暂无
暂无

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

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