Repository: beevelop/docker-nginx-basic-auth Branch: latest Commit: b2b12f843721 Files: 9 Total size: 12.3 KB Directory structure: gitextract_pa3lvg89/ ├── .github/ │ ├── dependabot.yml │ └── workflows/ │ └── docker.yml ├── Dockerfile ├── LICENSE ├── README.md ├── auth.conf ├── auth.htpasswd ├── docker-stack.yml └── launch.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/dependabot.yml ================================================ version: 2 updates: - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" open-pull-requests-limit: 1 groups: github-actions: patterns: - "*" - package-ecosystem: "docker" directory: "/" schedule: interval: "daily" open-pull-requests-limit: 1 groups: docker: patterns: - "*" ================================================ FILE: .github/workflows/docker.yml ================================================ name: Docker Image on: schedule: - cron: "0 10 * * *" # everyday at 10am workflow_dispatch: pull_request: branches: ["**"] push: branches: ["**"] tags: ["v*.*.*"] env: platforms: linux/amd64,linux/arm64/v8,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 jobs: main: runs-on: ubuntu-22.04 timeout-minutes: 10 steps: - name: Check out the repo uses: actions/checkout@v6 with: ref: ${{ github.head_ref || github.ref }} - name: Set imageName based on the repository name id: step_one run: | imageName="${GITHUB_REPOSITORY/docker-/}" echo $imageName echo "imageName=$imageName" >> $GITHUB_ENV - name: Docker meta id: docker_meta uses: docker/metadata-action@v6 with: images: ${{ env.imageName }} - name: Set up QEMU uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Login to DockerHub uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push id: docker_build uses: docker/build-push-action@v7 with: platforms: ${{ env.platforms }} push: ${{ github.event_name != 'pull_request' }} pull: true tags: ${{ steps.docker_meta.outputs.tags }} labels: ${{ steps.docker_meta.outputs.labels }} - name: Docker Scout id: docker-scout-cves if: ${{ github.event_name != 'pull_request' }} uses: docker/scout-action@v1 with: command: cves image: ${{ env.imageName }}:${{ steps.docker_meta.outputs.version }} only-severities: critical,high exit-code: false ================================================ FILE: Dockerfile ================================================ FROM nginx:alpine ENV HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \ FORWARD_PORT=80 \ FORWARD_HOST=web WORKDIR /opt RUN apk add --no-cache gettext COPY auth.conf auth.htpasswd launch.sh ./ # make sure root login is disabled RUN sed -i -e 's/^root::/root:!:/' /etc/shadow CMD ["./launch.sh"] ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2016-2021 Maik Hummel (beevelop) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-nginx-basic-auth/docker.yml?style=for-the-badge) ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/nginx-basic-auth.svg?style=for-the-badge) ![Docker Stars](https://img.shields.io/docker/stars/beevelop/nginx-basic-auth?style=for-the-badge) ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/beevelop/nginx-basic-auth/latest?style=for-the-badge) ![License](https://img.shields.io/github/license/beevelop/docker-nginx-basic-auth?style=for-the-badge) [![GitHub release](https://img.shields.io/github/release/beevelop/docker-nginx-basic-auth.svg?style=for-the-badge)](https://github.com/beevelop/docker-nginx-basic-auth/releases) ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-nginx-basic-auth?style=for-the-badge) ![CalVer](https://img.shields.io/badge/CalVer-YYYY.MM.MICRO-22bfda.svg?style=for-the-badge) [![Beevelop](https://img.shields.io/badge/-%20Made%20with%20%F0%9F%8D%AF%20by%20%F0%9F%90%9Dvelop-blue.svg?style=for-the-badge)](https://beevelop.com) # Docker Nginx Basic Auth - Simple Authentication Proxy > Lightweight nginx reverse proxy with HTTP basic authentication for securing Docker containers and web applications. ## Quickstart ```bash 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`. ## Advanced ```bash 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! ## Configuration - `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 forwarded - `FORWARD_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 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`). ## Troubleshooting **Error: `nginx: [emerg] host not found in upstream "web"`** - Ensure you link the container as `web` using `--link foobar:web` ## Limitations - SSL/HTTPS is not currently supported - For SSL requirements, consider using `jwilder/nginx-proxy` as a central gateway with `VIRTUAL_HOST` environment variable --- # All Docker Images | Badge | Pulls | Build Status | Release Date | Release | | --- | --- | --- | --- | --- | | [![base](https://img.shields.io/badge/beevelop%2Fbase-grey?style=flat-square&logo=github)](https://github.com/beevelop/docker-base) | ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/base.svg?style=flat-square) | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-base/docker.yml?style=flat-square) | ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-base?style=flat-square) | ![GitHub release](https://img.shields.io/github/release/beevelop/docker-base.svg?style=flat-square) | | [![java](https://img.shields.io/badge/beevelop%2Fjava-grey?style=flat-square&logo=github)](https://github.com/beevelop/docker-java) | ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/java.svg?style=flat-square) | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-java/docker.yml?style=flat-square) | ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-java?style=flat-square) | ![GitHub release](https://img.shields.io/github/release/beevelop/docker-java.svg?style=flat-square) | | [![android](https://img.shields.io/badge/beevelop%2Fandroid-grey?style=flat-square&logo=github)](https://github.com/beevelop/docker-android) | ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/android.svg?style=flat-square) | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-android/docker.yml?style=flat-square) | ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-android?style=flat-square) | ![GitHub release](https://img.shields.io/github/release/beevelop/docker-android.svg?style=flat-square) | | [![android-nodejs](https://img.shields.io/badge/beevelop%2Fandroid_nodejs-grey?style=flat-square&logo=github)](https://github.com/beevelop/docker-android-nodejs) | ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/android-nodejs.svg?style=flat-square) | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-android-nodejs/docker.yml?style=flat-square) | ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-android-nodejs?style=flat-square) | ![GitHub release](https://img.shields.io/github/release/beevelop/docker-android-nodejs.svg?style=flat-square) | | [![cordova](https://img.shields.io/badge/beevelop%2Fcordova-grey?style=flat-square&logo=github)](https://github.com/beevelop/docker-cordova) | ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/cordova.svg?style=flat-square) | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-cordova/docker.yml?style=flat-square) | ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-cordova?style=flat-square) | ![GitHub release](https://img.shields.io/github/release/beevelop/docker-cordova.svg?style=flat-square) | | [![ionic](https://img.shields.io/badge/beevelop%2Fionic-grey?style=flat-square&logo=github)](https://github.com/beevelop/docker-ionic) | ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/ionic.svg?style=flat-square) | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-ionic/docker.yml?style=flat-square) | ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-ionic?style=flat-square) | ![GitHub release](https://img.shields.io/github/release/beevelop/docker-ionic.svg?style=flat-square) | | [![nginx-basic-auth](https://img.shields.io/badge/beevelop%2Fnginx_basic_auth-grey?style=flat-square&logo=github)](https://github.com/beevelop/docker-nginx-basic-auth) | ![Docker Pulls](https://img.shields.io/docker/pulls/beevelop/nginx-basic-auth.svg?style=flat-square) | ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/beevelop/docker-nginx-basic-auth/docker.yml?style=flat-square) | ![GitHub Release Date](https://img.shields.io/github/release-date/beevelop/docker-nginx-basic-auth?style=flat-square) | ![GitHub release](https://img.shields.io/github/release/beevelop/docker-nginx-basic-auth.svg?style=flat-square) | --- ![Beevelop's Docker Image Hierarchy](https://gist.githubusercontent.com/beevelop/b0cddab7209a683c77560d06ff00bc8e/raw/15429ee1d02e2c4dc019b760ca8c7ceff5911b82/hierarchy.png) ### Use tags where possible, because ![One does not simply use latest](https://i.imgflip.com/1fgwxr.jpg) ================================================ FILE: auth.conf ================================================ server { listen 80 default_server; location / { auth_basic "Restricted"; auth_basic_user_file auth.htpasswd; proxy_pass http://${FORWARD_HOST}:${FORWARD_PORT}; proxy_read_timeout 900; } } ================================================ FILE: auth.htpasswd ================================================ ${HTPASSWD} ================================================ FILE: docker-stack.yml ================================================ version: '3.1' # run with docker-compose: # # docker-compose -f docker-stack.yml up # run with docker swarm: # # docker swarm init # docker stack deploy --compose-file docker-stack.yml authdemo volumes: web-data: services: web: image: 'nginx' ## instead of an exposed port, use FORWARD_PORT in auth, below # ports: # - '80:80' volumes: - web-data:/usr/share/nginx/html:ro auth: image: 'beevelop/nginx-basic-auth' ports: - '8080:80' environment: - PORT=80 - FORWARD_HOST=web - FORWARD_PORT=80 ## escape $ with $$ in Docker yml due to variable expansion ## example user/pass generated with htpasswd is foo:bar - HTPASSWD=foo:$$apr1$$odHl5EJN$$KbxMfo86Qdve2FH4owePn. ================================================ FILE: launch.sh ================================================ #!/bin/sh rm /etc/nginx/conf.d/default.conf || : envsubst < auth.conf > /etc/nginx/conf.d/auth.conf envsubst < auth.htpasswd > /etc/nginx/auth.htpasswd exec nginx -g "daemon off;"