简体   繁体   English

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

[英]How to build docker image from github repository

In official docs we can see:在官方文档中,我们可以看到:

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

It just works fine to me.它对我来说很好用。 docker-firefox is a repository and has Dockerfile within root dir. Dockerfile docker-firefox是一个存储库,在根目录中有Dockerfile
Then I want to buid redis image and exact version 2.8.10 :然后我想构建 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
)

I got error above.我上面有错误。 What's the right format with build docker image from github repos?从 github repos 构建 docker 镜像的正确格式是什么?

docker build url#ref:dir

Git URLs accept context configuration in their fragment section, separated by a colon :. Git URL 在它们的片段部分接受上下文配置,用冒号 : 分隔。 The first part represents the reference that Git will check out, this can be either a branch, a tag, or a commit SHA.第一部分代表 Git 将检出的引用,这可以是分支、标签或提交 SHA。 The second part represents a subdirectory inside the repository that will be used as a build context.第二部分表示存储库中的一个子目录,它将用作构建上下文。

For example, run this command to use a directory called docker in the branch container:例如,运行此命令以使用分支容器中名为 docker 的目录:

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

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

The thing you specified as repo URL is not a valid git repository.您指定为 repo URL 的内容不是有效的 git 存储库。 You will get error when you will try当你尝试时你会得到错误

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

Valid URL for this repo is github.com/docker-library/redis .此 repo 的有效 URL 是github.com/docker-library/redis So you may want to try following:因此,您可能想尝试以下操作:

docker build github.com/docker-library/redis

But this will not work too.但这也行不通。 To build from github, docker requires Dockerfile in repository root, howerer, this repo doesn't provide this one.为了从GitHub构建,码头工人需要Dockerfile在库的根,howerer,这种回购不提供这一个。 So, I suggest, you only have to clone this repo and build image using local Dockerfile.所以,我建议你只需要克隆这个 repo 并使用本地 Dockerfile 构建镜像。

One can use the following example which sets up a Centos 7 container for testing ORC file format.可以使用以下示例设置 Centos 7 容器来测试 ORC 文件格式。 Make sure to escape the # sign:确保转义#符号:

$ 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