I've got a single Redis instance up and running with docker-compose (using my Redis Dockerfile).
After the container has launched, I'm attempting to seed the Redis instance with data.
(1) Attempting to run redis-cli from the Dockerfile (that is run by docker-compose)
FROM redis:6.2.5
COPY ./redis.conf /test_dir/
COPY ./seed.txt /test_dir/
ENTRYPOINT ["redis-server", "/test_dir/redis.conf"]
RUN cat /test_dir/seed.txt | redis-cli -a <password> --pipe
This makes a mess. At 127.0.0.1:6379, we were unable to connect to Redis: The connection was rejected.
(2) A slightly different Dockerfile, which executes the same command in a shell script once the container starts:
FROM redis:6.2.5
COPY ./redis.conf /test_dir/
COPY ./seed.txt /test_dir/
COPY ./init.sh /test_dir/
ENTRYPOINT ["redis-server", "/test_dir/redis.conf"]
RUN . /test_dir/init.sh
# init.sh
sleep 10 # ensure Redis server is up and running
cat /test_dir/seed.txt | redis-cli -a <password> --pipe
The shell script runs, waits 10 seconds, and I double-checked that the server was up and running before triggering the data import, but Redis gets the same issue.
Notes:
(1) I've also removed'requirepass' and disabled 'protected-mode,' but redis-cli still won't connect.
(2) When I jump into the container and manually perform the command, it works!
So, how can I launch redis-cli from a Dockerfile or a shell script, and what is the best approach to seed a Docker Redis instance?
Thanks.