Skip to content

Commit

Permalink
Move "--protected-mode no" into the entrypoint instead
Browse files Browse the repository at this point in the history
Since doubling up on this option will have the "latest" version win, we're safe (in the sense of an image user being able to still override it) to apply this to all invocations of the server.

This change also includes the glue necessary to allow for `docker run redis --flag`, which frustrated me while I was testing this change.
  • Loading branch information
tianon committed May 10, 2016
1 parent 1d216ed commit e075dd9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
7 changes: 1 addition & 6 deletions 3.2/32bit/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@ COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 6379

# Disable Redis protected mode [1] as it is unnecessary in context
# of Docker. Ports are not automatically exposed when running inside
# Docker, but rather explicitely by specifying -p / -P.
# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
CMD [ "redis-server", "--protected-mode", "no" ]
CMD [ "redis-server" ]
17 changes: 16 additions & 1 deletion 3.2/32bit/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- redis-server "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
chown -R redis .
exec gosu redis "$0" "$@"
set -- gosu redis "$0" "$@"
fi

if [ "$1" = 'redis-server' ]; then
# Disable Redis protected mode [1] as it is unnecessary in context
# of Docker. Ports are not automatically exposed when running inside
# Docker, but rather explicitely by specifying -p / -P.
# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
shift # "redis-server"
set -- redis-server --protected-mode no "$@"
# if this is supplied again, the "latest" wins, so "--protected-mode no --protected-mode yes" will result in an enabled status
fi

exec "$@"
7 changes: 1 addition & 6 deletions 3.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,4 @@ COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 6379

# Disable Redis protected mode [1] as it is unnecessary in context
# of Docker. Ports are not automatically exposed when running inside
# Docker, but rather explicitely by specifying -p / -P.
# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
CMD [ "redis-server", "--protected-mode", "no" ]
CMD [ "redis-server" ]
7 changes: 1 addition & 6 deletions 3.2/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 6379

# Disable Redis protected mode [1] as it is unnecessary in context
# of Docker. Ports are not automatically exposed when running inside
# Docker, but rather explicitely by specifying -p / -P.
# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
CMD [ "redis-server", "--protected-mode", "no" ]
CMD [ "redis-server" ]
17 changes: 16 additions & 1 deletion 3.2/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- redis-server "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
chown -R redis .
exec su-exec redis "$0" "$@"
set -- su-exec redis "$0" "$@"
fi

if [ "$1" = 'redis-server' ]; then
# Disable Redis protected mode [1] as it is unnecessary in context
# of Docker. Ports are not automatically exposed when running inside
# Docker, but rather explicitely by specifying -p / -P.
# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
shift # "redis-server"
set -- redis-server --protected-mode no "$@"
# if this is supplied again, the "latest" wins, so "--protected-mode no --protected-mode yes" will result in an enabled status
fi

exec "$@"
17 changes: 16 additions & 1 deletion 3.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
#!/bin/sh
set -e

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- redis-server "$@"
fi

# allow the container to be started with `--user`
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
chown -R redis .
exec gosu redis "$0" "$@"
set -- gosu redis "$0" "$@"
fi

if [ "$1" = 'redis-server' ]; then
# Disable Redis protected mode [1] as it is unnecessary in context
# of Docker. Ports are not automatically exposed when running inside
# Docker, but rather explicitely by specifying -p / -P.
# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
shift # "redis-server"
set -- redis-server --protected-mode no "$@"
# if this is supplied again, the "latest" wins, so "--protected-mode no --protected-mode yes" will result in an enabled status
fi

exec "$@"

0 comments on commit e075dd9

Please sign in to comment.