如何从github库build立docker镜像

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

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

这对我来说工作得很好。 Dockerfile docker-firefox是一个仓库,在根目录下有Dockerfile
那么我想要build立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仓库build立docker的形象?

docker build uri#ref:dir

Git URLs在片段中接受上下文configuration,用冒号分隔。 第一部分代表Git将检出的引用,这可以是分支,标记或提交SHA。 第二部分表示将用作构build上下文的存储库内的子目录。

例如,运行此命令以在分支容器中使用名为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

此回购的有效url是github.com/docker-library/redis 。 所以你可能要尝试以下方法:

docker build github.com/docker-library/redis

但是这不会起作用。 要从github构build,docker需要在repository root中使用Dockerfile,但是这个repo不提供这个。 所以,我build议,你只需要克隆这个回购和使用本地Dockerfilebuild立图像。