From bf3e3c9fa814061a707b09f3763b97f097c95465 Mon Sep 17 00:00:00 2001 From: Joxit Date: Thu, 25 Jan 2018 18:39:47 +0100 Subject: [PATCH] Add REGISTRY_URL option for #25, this will avoid CORS errors --- Dockerfile.static | 1 + README.md | 18 ++++++++++++++++-- bin/entrypoint | 5 +++++ nginx/default.conf | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 nginx/default.conf diff --git a/Dockerfile.static b/Dockerfile.static index 6d6379f..d34e2a5 100644 --- a/Dockerfile.static +++ b/Dockerfile.static @@ -18,6 +18,7 @@ MAINTAINER Jones MAGLOIRE @Joxit WORKDIR /usr/share/nginx/html/ +COPY nginx/default.conf /etc/nginx/conf.d/default.conf COPY dist/ /usr/share/nginx/html/ COPY dist/scripts/script-static.js /usr/share/nginx/html/scripts/script.js COPY dist/scripts/tags-static.js /usr/share/nginx/html/scripts/tags.js diff --git a/README.md b/README.md index d77e043..27500c8 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This web user interface uses [Riot](https://github.com/Riot/riot) the react-like - One interface for many registries - Use a secured docker registry - Share your docker registry with query parameter `url` (e.g. `https://joxit.github.io/docker-registry-ui/demo?url=https://registry.example.com`) +- Use `joxit/docker-registry-ui:static` as reverse proxy to your docker registry (This will avoid CORS). ## Getting Started @@ -83,13 +84,26 @@ docker run -d -p 80:80 joxit/docker-registry-ui Some env options are available for use this interface for only one server. -- `URL`: set the static URL to use. (`Required`) -- `DELETE_IMAGES`: if this variable is empty or `false`, delete feature is desactivated. It is activated otherwise. +- `URL`: set the static URL to use (You will need CORS configuration). Example: `http://127.0.0.1:5000`. (`Required`) +- `REGISTRY_URL`: your docker registry URL to contact (CORS configuration is not needed). Example: `http://my-docker-container:5000`. (Can't be used with `URL`, since 0.3.2). +- `DELETE_IMAGES`: if this variable is empty or `false`, delete feature is deactivated. It is activated otherwise. + +Example with `URL` option. ```sh docker run -d -p 80:80 -e URL=http://127.0.0.1:5000 -e DELETE_IMAGES=true joxit/docker-registry-ui:static ``` +Example with `REGISTRY_URL`, this will add a proxy to your registry. +Your registry will be accessible here : `http://127.0.0.1/v2`, this will avoid CORS errors (see #25). +Be careful, `joxit/docker-registry-ui` and `registry:2` will communicate, both containers should be in the same network or use your private IP. + +```sh +docker network create registry-ui-net +docker run -d --net registry-ui-net --name registry-srv registry:2 +docker run -d --net registry-ui-net -p 80:80 -e REGISTRY_URL=http://registry-srv:5000 -e DELETE_IMAGES=true joxit/docker-registry-ui:static +``` + ## Using CORS Your server should be configured to accept CORS. diff --git a/bin/entrypoint b/bin/entrypoint index fb8734c..7cb269c 100755 --- a/bin/entrypoint +++ b/bin/entrypoint @@ -6,6 +6,11 @@ if [ -z "${DELETE_IMAGES}" ] || [ "${DELETE_IMAGES}" = false ] ; then sed -i "s/registryUI.isImageRemoveActivated *= *[^,;]*/registryUI.isImageRemoveActivated=false/" scripts/script.js fi +if [ -n "${REGISTRY_URL}" ] ; then + sed -i "s,\${REGISTRY_URL},${REGISTRY_URL}," /etc/nginx/conf.d/default.conf + sed -i "s,#!,," /etc/nginx/conf.d/default.conf +fi + if [ -z "$@" ]; then nginx -g "daemon off;" else diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..4e0c2e8 --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,34 @@ +server { + listen 80; + server_name localhost; +#! resolver 127.0.0.11; # This is for docker container name resolver + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + +#! location /v2 { +#! set $upstream ${REGISTRY_URL}; +#! proxy_pass $upstream; +#! } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} +