I'm trying to run multiple redis containers that use the same Dockerfile to setup their start scripts containing their start parameters like passwords, host binding, log levels, etc.
start-cache.sh
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
redis-server --bind ${CACHE_REDIS_HOST} --save 60 1 --loglevel warning --requirepass ${CACHE_REDIS_PASSWORD}
The second one looks exactly like that but with tweaked parameters ofc.
My dockerfile utilizing these start scripts looks like this:
FROM redis:7.2.1-alpine
COPY ./compose/local/redis/cache/start-cache.sh /start-cache
RUN sed -i 's/\r$//g' /start-cache
RUN chmod +x /start-cache
COPY ./compose/local/redis/media/start-media.sh /start-media
RUN sed -i 's/\r$//g' /start-media
RUN chmod +x /start-media
My docker compose utilizing the Dockerfile looks like this:
....
media-cache:
container_name: 'media_cache'
build:
context: .
dockerfile: ./compose/local/redis/Dockerfile
command: /start-media
env_file:
- .env
ports:
- 6371:6379
volumes:
- ./data/mediaRedis:/data
- ./compose/local/redis/redis.conf:/etc/redis/redis.conf
restart: always
db-cache:
container_name: 'db_cache'
build:
context: .
dockerfile: ./compose/local/redis/Dockerfile
command: /start-cache
env_file:
- .env
ports:
- 6370:6379
volumes:
- ./data/dbRedis:/data
- ./compose/local/redis/redis.conf:/etc/redis/redis.conf
restart: always
....
Don't believe it has any relevancy for my problem but just so it's out of the way, the redis.conf looks like this:
bind 0.0.0.0
My docker compose spits out the following errors concerning my redis containers before having both containers exit with code 0:
/usr/local/bin/docker-entrypoint.sh: exec: line 24: /start-media: not found
/usr/local/bin/docker-entrypoint.sh: exec: line 24: /start-cache: not found
Thanks in advance.
The "shebang" line at the very start of your script says it uses /bin/bash
. Alpine Linux doesn't normally contain bash or any other GNU tools.
Your script isn't using any shell features that aren't part of the POSIX shell standard, except for some set
options that won't matter here. You can change the script to use plain /bin/sh
, and remove the set
options
#!/bin/sh
exec redis-server \
--bind ${CACHE_REDIS_HOST} \
--save 60 1 \
--loglevel warning \
--requirepass ${CACHE_REDIS_PASSWORD}
You can also provide these options directly in the Compose command:
without using a script, if you'd prefer. The redis
image knows how to inject a redis-server
command if it's not explicitly specified, so you might be able to say
services:
media-cache:
image: redis:7.2.1-alpine
command: >
--bind 0.0.0.0
--save 60 1
--loglevel warning
--requirepass ${CACHE_REDIS_PASSWORD}
env_file:
- .env
ports:
- 6371:6379
volumes:
- ./data/mediaRedis:/data
- ./compose/local/redis/redis.conf:/etc/redis/redis.conf
restart: always
With this specific construction, the $CACHE_REDIS_PASSWORD
would need to be in the host environment or a .env
file; it is processed before the Compose environment:
or env_file:
directives are read.