My Redis container is defined as a standard image in my docker_compose.yml
:
redis:
image: redis
ports:
- "6379"
I guess it's using standard settings like binding to Redis at localhost
.
I need to bind it to 0.0.0.0, is there any way to add a local redis.conf
file to change the binding and let docker-compose
use it?
Yes. Mount the config into the image with a volume and modify the command to call it e.g:
redis:
image: redis
command: redis-server /usr/local/etc/redis/redis.conf
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf
ports:
- "6379"
Alternatively, create a new image based on the redis image with your conf file copied in. Full instructions are at: https://registry.hub.docker.com/_/redis/
However, the redis image does bind to 0.0.0.0
by default. To access it from the host, you need to use the port that Docker has mapped to the host for you which you find by using docker ps
or the docker port
command, you can then access it at localhost:32678
where 32678 is the mapped port. Alternatively, you can specify a specific port to map to in the docker-compose.yml
.
As you seem to be new to Docker, this might all make a bit more sense if you start by using raw Docker commands rather than starting with Compose.