I'm trying to create a Redis Docker image, based on the redis:3. However, I need to load a small amount of test data into the image (it is used for testing, both on developer machines and on the CI server).
My initial attempt looks like:
FROM redis:3.0.3
MAINTAINER Howard M. Lewis Ship
RUN redis-cli sadd production-stores 5555
But this fails with the error:
Step 2 : RUN redis-cli sadd production-stores 5555
---> Running in 60fb98c133c0
Could not connect to Redis at 127.0.0.1:6379: Connection refused
The command '/bin/sh -c redis-cli sadd production-stores 5555' returned a non-zero code: 1
I'm wondering if there's a trick that allows me, in a Docker file, to connect to the server started via the CMD/ENTRYPOINT of the Dockerfile. As I'm guessing right now, the RUN occurs before the command is started.
Alternately, is there a Redis command or trick that would allow me to load some data into its database.
I suspect one approach would be to mount the Redis' data directory in a volume exposed to the Docker host; this is not ideal as
The error tells Redis service is not started before you run redis-cli.
Add a new line to start it first. Let me know if this can fix your issue or not.
FROM redis:3.0.3
MAINTAINER Howard M. Lewis Ship
RUN /usr/sbin/redis-server /etc/redis.conf
RUN redis-cli sadd production-stores 5555
Review the official redis image, it has given the way to use redis-cli
# via redis-cli
$ docker run -it --link some-redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
So I test the image and make it run as below:
# start redis container
$ docker run --name some-redis -d redis
# link redis container and run redis-cli command
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis
redis:6379> PING
PONG
redis:6379> exit
# Add the specified members to the set stored at key
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis sadd production-stores 5555
(integer) 1
$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With