Skip to content

Run server with custom config #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ivanovaleksey opened this issue Feb 4, 2018 · 12 comments
Closed

Run server with custom config #125

ivanovaleksey opened this issue Feb 4, 2018 · 12 comments

Comments

@ivanovaleksey
Copy link

Hello,
I try to run redis server with a custom config via docker compose.

I got the following docker-compose.yml file:

version: '3'
services:
  web:
    build: .
    command: bundle exec puma -C config/puma.rb
    volumes:
      - ./log:/app/log
      - ./tmp:/app/tmp
    ports:
      - 9292:9292
    environment:
      - RACK_ENV=production
      - REDIS_URL=redis://redis:6379
    depends_on:
      - redis
  redis:
    image: redis:alpine
    volumes:
      - ./config/redis/redis.conf:/usr/local/etc/redis/redis.conf
    command:
      - redis-server /usr/local/etc/redis/redis.conf

Unfortunately, I got an error:

$ docker-compose up
redis_1  | 1:C 04 Feb 21:06:51.504 # Fatal error, can't open config file 'redis-server /usr/local/etc/redis/redis.conf'
redis_1 exited with code 1
web_1    | Puma starting in single mode...
web_1    | * Version 3.11.2 (ruby 2.5.0-p0), codename: Love Song
web_1    | * Min threads: 1, max threads: 1
web_1    | * Environment: production
web_1    | * Listening on tcp://0.0.0.0:9292
web_1    | Use Ctrl-C to stop

However, the file does exist. I can run redis service and see it
$ docker-compose run redis /bin/sh

$ ls -lt /usr/local/etc/redis/redis.conf
-rw-rw-r--    1 1000     1000         57845 Feb  4 20:43 /usr/local/etc/redis/redis.conf

It is strange to me that user and group is 1000.
Maybe it causes the issue?
Could you please help to figure it out?

@yosifkit
Copy link
Contributor

yosifkit commented Feb 5, 2018

The ownership of the file would be the cause of the problem (or possibly folder permissions, since /usr/local/etc/ does not exist and would be created by Docker in making the mount). You have a few options, run the container as your user (user: '1000:1000' in your yaml file) which can work because of #48, or maybe putting the file in a different location in the container would help.

@ivanovaleksey
Copy link
Author

Thank you for the reply @yosifkit.
I have tried /usr/local/redis.conf and /etc/redis.conf.
Now it is

-rw-r--r--    1 1000     50           57845 Feb  4 20:41 redis.conf

Where do these ids came from? Why it isn't root or redis?

@tianon
Copy link
Contributor

tianon commented Feb 5, 2018

Usernames are an abstraction -- the filesystem deals in raw UIDs, so as far as the kernel is concerned, root and redis don't mean anything. Those name conversions come from a file located at /etc/passwd, which is different on your Docker host system from the one inside the container, which is likely part of the issue you're seeing. If you don't supply --user or user: when running the redis image, it will step down from root by itself:

https://github.com/docker-library/redis/blob/d53b982b387634092c6f11069401679034054ecb/4.0/docker-entrypoint.sh#L10-L14

As for why you're seeing those specific values, I'd imagine it probably has something to do with your docker-compose.yml or your host filesystem. It sounds like you're probably using Docker Toolbox with boot2docker (since boot2docker uses 1000:50 as the default user for the filesystem share into the Docker VM), but that's just a guess.

Since this isn't really an issue with the image, and is more of a question about usage, I'm going to close.
In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow. Thanks!

@tianon tianon closed this as completed Feb 5, 2018
@ivanovaleksey
Copy link
Author

Thanks, I will try to investigate further.

@ivanovaleksey
Copy link
Author

ivanovaleksey commented Feb 6, 2018

@tianon @yosifkit
As it turned out one should command in the following way:

redis:
    image: redis:alpine
    volumes:
      - ./config/redis/redis.conf:/usr/local/etc/redis/redis.conf
    command:
      - /usr/local/etc/redis/redis.conf

This way docker-entrypoint.sh works fine and rewrite the whole command to

# set -- redis-server "$@"
redis-server /usr/local/etc/redis/redis.conf

In my first message I got error

can't open config file 'redis-server /usr/local/etc/redis/redis.conf'

So, the whole command was interpreted as file name.

Now config file was read but I got another error:

redis_1  | *** FATAL CONFIG FILE ERROR ***
redis_1  | Reading the configuration file, at line 172
redis_1  | >>> 'logfile /var/log/redis_6379.log'
redis_1  | Can't open the log file: Permission denied

P.S.
I have changed logfile /var/log/redis_6379.log to logfile /data/redis_6379.log but the file remains the same. Looks like it was cached somehow thought I have cleared volumes.

@wolfpack94
Copy link

Any update on this error?

@yosifkit
Copy link
Contributor

yosifkit commented Sep 6, 2018

@wolfpack94, to what error are you referring? The original issue was that the yaml was wrongly configured.

# it was this
    command:
      - redis-server /usr/local/etc/redis/redis.conf

# when it should've been this
    command:
      - redis-server
      - /usr/local/etc/redis/redis.conf

# or this
    command:
      - /usr/local/etc/redis/redis.conf

@phpguru
Copy link

phpguru commented Apr 14, 2020

Make sure to use daemonize no in your custom config. Redis is automagically daemonized by the Docker entry_point.sh

Changing daemonize from yes to no worked fine for me.

@bmy4415
Copy link

bmy4415 commented May 22, 2020

@phpguru has exactly same with my situation.
When I use daemonize yes in my redis.conf file, redis container terminate right after startup.
Even this does not show helpful logs.

$ docker logs -ft redis
2020-05-22T07:06:33.532775512Z 1:C 22 May 2020 07:06:33.532 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2020-05-22T07:06:33.532815657Z 1:C 22 May 2020 07:06:33.532 # Redis version=6.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
2020-05-22T07:06:33.532822149Z 1:C 22 May 2020 07:06:33.532 # Configuration loaded

# end of log

@tungrix

This comment was marked as off-topic.

@LaurentGoderre

This comment was marked as off-topic.

@yosifkit

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants