Docker-compose , anyway to specify a redis.conf file?

Yes. Just mount your redis.conf over the default with a volume:

redis:  
  image: redis
  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.


Old question, but if someone still want to do that, it is possible with volumes and command:

command: redis-server /usr/local/etc/redis/redis.conf
volumes:
 - ./redis/redis.conf:/usr/local/etc/redis/redis.conf

Unfortunately with Docker, things become a little tricky when it comes to Redis configuration file, and the answer voted as best (im sure from people that did'nt actually tested it) it DOESNT work.

But what DOES WORK, fast, and without husles is this:

 command: redis-server --bind redis-container-name --requirepass some-long-password --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes

You can pass all the variable options you want in the command section of the yaml docker file, by adding "--" in the front of it, followed by the variable value.

Never forget to set a password, and if possible close the port 6379.

Τhank me later.

PS: If you noticed at the command, i didnt use the typical 127.0.0.1, but instead the redis container name. This is done for the reason that docker assigns ip addresses internally via it's embedded dns server. In other words this bind address becomes dynamic, hence adding an extra layer of security.

If your redis container is called "redis" and you execute the command docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis (for verifying the running container's internal ip address), as far as docker is concerned, the command give in docker file, will be translated internally to something like: redis-server --bind 172.19.0.5 --requirepass some-long-password --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes