I run the official Redis image https://hub.docker.com/_/redis/ in a docker-compose
setup.
myredis:
image: redis
How can run redis-cli
with docker-compose on that image?
I tried the following, but it didn't connect:
docker-compose run myredis redis-cli
> Could not connect to Redis at 127.0.0.1:6379: Connection refuse
The docs of the image says that I should run:
docker run -it --rm \
--link some-redis:redis \
redis \
sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
How does this translate to docker-compose run
?
You can also use this command:
That would override the default
CMD [ "redis-server" ]
: you are trying to runredis-cli
on a container where theredis-server
was never executed.As mentioned here, you can also test with:
From docker-compose, as mentioned in this docker/compose issue 2123:
As the OP ivoba confirms (in the comments), the last form works.
Then:
ivoba also adds:
I followed as @VonC suggest, but in my case I run redis on predefined network so it did not worked.
So in the case redis container run in specific network,
network
field should be specified in docker-compose.yaml file