Skip to content

Instantly share code, notes, and snippets.

@vbatts
Last active August 29, 2015 13:57
Show Gist options
  • Save vbatts/9474572 to your computer and use it in GitHub Desktop.
Save vbatts/9474572 to your computer and use it in GitHub Desktop.

== For a static file-system (not an interactive registry daemon)

-- Overview For use-cases of serving docker images from a registry, that is to be read-only (pull or run, no push). It is necessary to make certain aspects of the index/registry API optional. This way the HTTP GET's made for pulling an image and layers, are provided by a basic file system server and no added logic.

Presently, there are a few custom headers that are expected of the registry, by the docker tool. If the headers are not present, then the pull of the image fails. The functionality that is using these headers ought to have some sane defaults if they are not present.

-- Example Using the attached server (though any http server like httpd or lighttpd would work too), to serve a directory. The directory fetched from http://people.gnome.org/~alexl/v1.tar.gz, looks like:

$ find . -type f
./v1/repositories/busybox/images
./v1/repositories/library/busybox/tag_latest
./v1/repositories/library/busybox/tags
./v1/_ping
./v1/images/e9aa60c60128cad1/layer
./v1/images/e9aa60c60128cad1/_checksum
./v1/images/e9aa60c60128cad1/json
./v1/images/e9aa60c60128cad1/ancestry
$ echo '{"version":"0.1.1", "standalone":true}' > _ping
$ go build ~/fileserver.go
$ ./fileserver .
2014/03/10 17:13:21 serving "." listening on 127.0.0.1:8080 ...


Using my branch of docker for making these headers optional (https://github.com/vbatts/docker/tree/vbatts-static_registry).

$ ./bundles/0.8.1-dev/dynbinary/docker-0.8.1-dev run -i -t localhost:8080/busybox sh
Unable to find image 'localhost:8080/busybox' locally
Pulling repository localhost:8080/busybox
e9aa60c60128: Download complete


BusyBox v1.19.3 (Ubuntu 1:1.19.3-7ubuntu1.1) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/ #
package main
import (
"flag"
"fmt"
"log"
"net/http"
"runtime"
)
func main() {
var (
bind = flag.String("b", "127.0.0.1", "address to bind on")
port = flag.String("p", "8080", "port to listen on")
cpus = flag.Int("c", 1, "CPUs to use")
path = "/tmp"
)
flag.Parse()
runtime.GOMAXPROCS(*cpus)
if flag.NArg() > 0 {
path = flag.Args()[0]
}
addr := fmt.Sprintf("%s:%s", *bind, *port)
http.Handle("/", http.FileServer(http.Dir(path)))
log.Printf("serving %q listening on %s ...", path, addr)
log.Fatal(http.ListenAndServe(addr, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment