Simple Docker image for basic authentication with envs
10K+
Can use NGINX_PORT and NGINX_HOST:
> docker run --rm \
-p 7070:7070 \
-e NGINX_PORT=7070 \
-e NGINX_HOST=localhost \
-e FORWARD_PORT=8888 \
-e FORWARD_HOST=nginx \
-e HTPASSWD='username:$apr1$0SUNY6DM$/DAoI2uFeZlbwwr9IVC0t0' \
a00s/docker-nginx-basic-auth-with-env:1.21.1-alpine-1
> curl localhost:7070/health
OK
> curl localhost:7070
~~~ basic auth to nginx:8888
Simple Docker image to provide basic authentication for a single other container.
docker run -d --name web dockercloud/hello-world
docker run -d -p 80:80 --link web:web --name auth beevelop/nginx-basic-auth
Try accessing and logging in with username foo and password bar.
docker run -d \
-e HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \
-e FORWARD_PORT=1337 \
--link web:web -p 8080:80 \
--name auth \
beevelop/nginx-basic-auth
Use single quotes to prevent unwanted interpretation of
$signs!
HTPASSWD (default: foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.): Will be written to the .htpasswd file on launch (non-persistent)FORWARD_PORT (default: 80): Port of the source container that should be forwardedFORWARD_HOST (default: web): Hostname of the source container that should be forwarded
The container does not need any volumes to be mounted! Nonetheless you will find all interesting files at
/etc/nginx/*.
Multiple Users are possible by separating the users by newline. To pass the newlines properly you need to use Shell Quoting (like $'foo\nbar'):
docker run -d --link web:web --name auth \
-e HTPASSWD=$'foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.\ntest:$apr1$LKkW8P4Y$P1X/r2YyaexhVL1LzZAQm.' \
beevelop/nginx-basic-auth
results in 2 users (foo:bar and test:test).
nginx: [emerg] host not found in upstream "web" in /etc/nginx/conf.d/auth.conf:80
web (--link foobar:web)jwilder/nginx-proxy) that acts as a central gateway. You just need to configure the VIRTUAL_HOST env and disable port forwarding.Content type
Image
Digest
Size
11.1 MB
Last updated
over 4 years ago
docker pull a00s/docker-nginx-basic-auth-with-env:1.21.1-alpine-5