Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for docker secrets #355

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ For more information about the full official images change lifecycle, see [the "

For outstanding `redis` image PRs, check [PRs with the "library/redis" label on the official-images repository](https://github.com/docker-library/official-images/labels/library%2Fredis). For the current "source of truth" for [`redis`](https://hub.docker.com/_/redis/), see [the `library/redis` file in the official-images repository](https://github.com/docker-library/official-images/blob/master/library/redis).

## Docker secrets
To pass the value for `--requirepass` password in a secure way docker secrets can be used.

```
version: '3'
services:
redis:
image: redis:alpine
environment:
- REDIS_PASSWORD_FILE=/run/secrets/REDIS_PASSWORD
secrets:
- REDIS_PASSWORD

secrets:
REDIS_PASSWORD:
file: ./.secrets/REDIS_PASSWORD
```
Default for REDIS_PASSWORD_FILE is already `/run/secrets/REDIS_PASSWORD`. It is therefore here optional if the secret is named `REDIS_PASSWORD`

---

- [![build status badge](https://img.shields.io/github/actions/workflow/status/docker-library/redis/ci.yml?branch=master&label=GitHub%20CI)](https://github.com/docker-library/redis/actions?query=workflow%3A%22GitHub+CI%22+branch%3Amaster)
Expand Down
8 changes: 8 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
set -- redis-server "$@"
fi

# if secret REDIS_PASSWORD exists or REDIS_PASSWORD_FILE is set use content for requirepass
if [ "$1" = 'redis-server' -a -s "${REDIS_PASSWORD_FILE:=/run/secrets/REDIS_PASSWORD}" ]; then
if ! printf '%s\n' "$@" | grep -Fqe "--requirepass"; then
REDIS_PASSWORD=$(cat "${REDIS_PASSWORD_FILE}")
set -- "$@" --requirepass "${REDIS_PASSWORD}"
fi
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
find . \! -user redis -exec chown redis '{}' +
Expand Down