From ce0b370dd02c6c61188ddc4ddd70fc88fec9ec48 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 9 Apr 2015 13:23:21 -0700 Subject: [PATCH] Add docker compose configuration for v1 and v2 Signed-off-by: Derek McGowan (github: dmcgowan) --- contrib/compose/README.md | 23 ++++++++++++ contrib/compose/docker-compose.yml | 15 ++++++++ contrib/compose/nginx/Dockerfile | 6 ++++ contrib/compose/nginx/docker-registry-v2.conf | 4 +++ contrib/compose/nginx/docker-registry.conf | 5 +++ contrib/compose/nginx/nginx.conf | 27 ++++++++++++++ contrib/compose/nginx/registry.conf | 36 +++++++++++++++++++ 7 files changed, 116 insertions(+) create mode 100644 contrib/compose/README.md create mode 100644 contrib/compose/docker-compose.yml create mode 100644 contrib/compose/nginx/Dockerfile create mode 100644 contrib/compose/nginx/docker-registry-v2.conf create mode 100644 contrib/compose/nginx/docker-registry.conf create mode 100644 contrib/compose/nginx/nginx.conf create mode 100644 contrib/compose/nginx/registry.conf diff --git a/contrib/compose/README.md b/contrib/compose/README.md new file mode 100644 index 000000000..e6f618150 --- /dev/null +++ b/contrib/compose/README.md @@ -0,0 +1,23 @@ +# Docker Compose V1 + V2 registry + +This compose configuration will setup a v1 and v2 registry behind an nginx +proxy. By default the combined registry may be accessed at localhost:5000. +This registry does not support pushing images to v2 and pull from v1. Clients +from before 1.6 will be configured to use the v1 registry, and newer clients +will use the v2 registry. + +## Prerequisites +Install [docker-compose](https://github.com/docker/compose) + +## How to run +``` +$ docker-compose up +``` + +## How to push images +From a local project directory with Dockerfile +``` +$ docker build -t localhost:5000/myimage . +$ docker push localhost:5000/myimage +``` + diff --git a/contrib/compose/docker-compose.yml b/contrib/compose/docker-compose.yml new file mode 100644 index 000000000..5cd048588 --- /dev/null +++ b/contrib/compose/docker-compose.yml @@ -0,0 +1,15 @@ +nginx: + build: "nginx" + ports: + - "5000:5000" + links: + - registryv1:registryv1 + - registryv2:registryv2 +registryv1: + image: registry + ports: + - "5000" +registryv2: + build: "../../" + ports: + - "5000" diff --git a/contrib/compose/nginx/Dockerfile b/contrib/compose/nginx/Dockerfile new file mode 100644 index 000000000..2b252ec7d --- /dev/null +++ b/contrib/compose/nginx/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx:1.7 + +COPY nginx.conf /etc/nginx/nginx.conf +COPY registry.conf /etc/nginx/conf.d/registry.conf +COPY docker-registry.conf /etc/nginx/docker-registry.conf +COPY docker-registry-v2.conf /etc/nginx/docker-registry-v2.conf diff --git a/contrib/compose/nginx/docker-registry-v2.conf b/contrib/compose/nginx/docker-registry-v2.conf new file mode 100644 index 000000000..c48886db9 --- /dev/null +++ b/contrib/compose/nginx/docker-registry-v2.conf @@ -0,0 +1,4 @@ +proxy_pass http://docker-registry-v2; +proxy_set_header Host $http_host; # required for docker client's sake +proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP +proxy_read_timeout 900; diff --git a/contrib/compose/nginx/docker-registry.conf b/contrib/compose/nginx/docker-registry.conf new file mode 100644 index 000000000..bdcf3a34a --- /dev/null +++ b/contrib/compose/nginx/docker-registry.conf @@ -0,0 +1,5 @@ +proxy_pass http://docker-registry; +proxy_set_header Host $http_host; # required for docker client's sake +proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP +proxy_set_header Authorization ""; # see https://github.com/docker/docker-registry/issues/170 +proxy_read_timeout 900; diff --git a/contrib/compose/nginx/nginx.conf b/contrib/compose/nginx/nginx.conf new file mode 100644 index 000000000..63cd180d6 --- /dev/null +++ b/contrib/compose/nginx/nginx.conf @@ -0,0 +1,27 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + + keepalive_timeout 65; + + include /etc/nginx/conf.d/*.conf; +} + diff --git a/contrib/compose/nginx/registry.conf b/contrib/compose/nginx/registry.conf new file mode 100644 index 000000000..28542a47c --- /dev/null +++ b/contrib/compose/nginx/registry.conf @@ -0,0 +1,36 @@ +# Docker registry proxy for api versions 1 and 2 + +upstream docker-registry { + server registryv1:5000; +} + +upstream docker-registry-v2 { + server registryv2:5000; +} + +# No client auth or TLS +server { + listen 5000; + server_name localhost; + + # disable any limits to avoid HTTP 413 for large image uploads + client_max_body_size 0; + + # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486) + chunked_transfer_encoding on; + + location /v2/ { + # Do not allow connections from docker 1.5 and earlier + # docker pre-1.6.0 did not properly set the user agent on ping, catch "Go *" user agents + if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) { + return 404; + } + + include docker-registry-v2.conf; + } + + location / { + include docker-registry.conf; + } +} +