Skip to content

Commit f4d3476

Browse files
committed
create a private authenticated local repository
1 parent 60dee43 commit f4d3476

13 files changed

Lines changed: 129 additions & 33 deletions

File tree

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ Developer forum for [docker-java](https://groups.google.com/forum/?hl=de#!forum/
1717
* Docker daemon running
1818
* Docker private repository running (see below).
1919

20-
You'll need to be running a local private registry, as per [the quick start instructions](https://github.com/docker/docker-registry):
21-
22-
$ docker run -p 5000:5000 registry
23-
24-
If you're using boot2docker, set-up a port forward:
25-
26-
$ VBoxManage controlvm boot2docker-vm natpf1 "5000,tcp,127.0.0.1,5000,,5000"
27-
28-
You can remove this forward later using:
29-
30-
$ VBoxManage controlvm boot2docker-vm natpf1 delete 5000
20+
You'll need to be running a local private registry, as per [these instructions](docker-auth-registry/README.md):
3121

3222
The Maven build includes integration tests which are using a localhost instance of Docker and require manual setup. Make sure you have a local Docker daemon running and then provide your https://registry.hub.docker.com/account/login/ information via system properties:
3323

build-docker-registry.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /bin/sh
2+
set -eux
3+
4+
git clone https://github.com/docker/docker-registry
5+
cp docker-registry/contrib/nginx/nginx_1–3–9.conf /etc/nginx/conf.d/

docker-auth-registry/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://medium.com/@deeeet/building-private-docker-registry-with-basic-authentication-with-self-signed-certificate-using-it-e6329085e612
2+
3+
FROM registry
4+
5+
RUN apt-get update
6+
RUN apt-get install -y nginx
7+
8+
ADD nginx.conf /etc/nginx/
9+
ADD docker-registry.conf /etc/nginx/
10+
11+
ADD docker-registry.htpasswd /etc/nginx/
12+
13+
EXPOSE 5001
14+
15+
ADD start.sh .
16+
17+
CMD ./start.sh

docker-auth-registry/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Set-up a Docker Registry with Plain Text Authentication
2+
--
3+
4+
This creates a registry that runs locally with plain text authentication set-up.
5+
6+
./build.sh
7+
./run.sh
8+
./test.sh

docker-auth-registry/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/sh
2+
set -eux
3+
4+
docker build -t auth-registry .
5+
6+
if [ "$(which boot2docker)" != "" ]; then
7+
VBoxManage controlvm boot2docker-vm natpf1 "5001,tcp,127.0.0.1,5001,,5001" || true
8+
fi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proxy_pass http://docker-registry;
2+
proxy_set_header Host $http_host; # required for docker client's sake
3+
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
4+
proxy_set_header Authorization ""; # see https://github.com/dotcloud/docker-registry/issues/170
5+
proxy_read_timeout 900;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker-java:$apr1$nhxYQXIn$s93lYeFNs66YAXwQerlHL0

docker-auth-registry/nginx.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
http {
2+
# FYI: Chunking requires nginx-extras package on Debian Wheezy and some Ubuntu versions
3+
# See chunking http://wiki.nginx.org/HttpChunkinModule
4+
# Replace with appropriate values where necessary
5+
6+
upstream docker-registry {
7+
server localhost:5000;
8+
}
9+
10+
# uncomment if you want a 301 redirect for users attempting to connect
11+
# on port 80
12+
# NOTE: docker client will still fail. This is just for convenience
13+
# server {
14+
# listen *:80;
15+
# server_name my.docker.registry.com;
16+
# return 301 https://$server_name$request_uri;
17+
# }
18+
19+
server {
20+
listen 5001;
21+
server_name my.docker.registry.com;
22+
23+
client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
24+
25+
location / {
26+
auth_basic "Restricted";
27+
auth_basic_user_file docker-registry.htpasswd;
28+
include docker-registry.conf;
29+
}
30+
31+
location /_ping {
32+
auth_basic off;
33+
include docker-registry.conf;
34+
}
35+
36+
location /v1/_ping {
37+
auth_basic off;
38+
include docker-registry.conf;
39+
}
40+
}
41+
}
42+
events {
43+
worker_connections 1024;
44+
}

docker-auth-registry/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/sh
2+
set -eux
3+
4+
docker kill $(docker ps -q) || true
5+
6+
docker run -p 5001:5001 auth-registry

docker-auth-registry/start.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/sh
2+
set -eux
3+
4+
docker-registry &
5+
nginx
6+
7+
wait
8+

0 commit comments

Comments
 (0)