Docker Redis - Seeding Data - Cannot execute redis-cli via Dockerfile or via shell script

0 votes

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.

Apr 29, 2022 in Docker by Abhijeet
• 180 points

edited 5 days ago 11 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP