48

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.
Then I want to buid redis image and exact version 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?

seanlook
  • 907
  • 2
  • 9
  • 13

3 Answers3

53

docker build url#ref:dir

Git URLs accept context configuration in their fragment section, separated by a colon :. The first part represents the reference that Git will check out, this can be either a branch, a tag, or a commit 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 build https://github.com/docker/rootfs.git#container:docker

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

rofrol
  • 14,438
  • 7
  • 79
  • 77
11

The thing you specified as repo URL is not a valid git repository. 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. 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. So, I suggest, you only have to clone this repo and build image using local Dockerfile.

Viacheslav Kovalev
  • 1,745
  • 12
  • 17
  • 3
    In fact `docker build https://raw.githubusercontent.com/docker-library/redis/master/2.8.10/Dockerfile` works, but not like the [official example](http://docs.docker.com/v1.1/reference/commandline/cli/#build). Thanks for your answer. – seanlook Nov 05 '14 at 12:58
5

One can use the following example which sets up a Centos 7 container for testing ORC file format. Make sure to escape the # sign:

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

Pratik Khadloya
  • 12,509
  • 11
  • 81
  • 106
  • 1
    The "-t" flag and name is important in order the image gets a name set. Otherwise you'll end up with images. – david Jan 15 '20 at 16:30
  • 1
    I don't know why it fails on my computer. The error says "failed to solve with frontend dockerfile.v0: failed to read dockerfile: failed to load cache key: subdir not supported yet". I'm using Docker-CE-20.10 – runzhi xiao Dec 07 '21 at 08:01