Skip to content
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

Unable to log to bind mount #405

Open
krbob opened this issue Jul 24, 2024 · 2 comments
Open

Unable to log to bind mount #405

krbob opened this issue Jul 24, 2024 · 2 comments

Comments

@krbob
Copy link

krbob commented Jul 24, 2024

I have two containers in my Docker Compose stack running with non-root user permissions: Redis and MariaDB.

mariadb:
  container_name: mariadb
  build:
    context: mariadb
  volumes:
    - ${LOGS_DIRECTORY}/mariadb:/var/log/mysql

redis:
  container_name: redis
  build:
    context: redis
  volumes:
    - ${LOGS_DIRECTORY}/redis:/var/log/redis

I created similar Dockerfiles for both of them:

# Redis
FROM redis:6.2-bookworm

COPY my-entrypoint.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/my-entrypoint.sh

ENTRYPOINT ["my-entrypoint.sh"]

CMD ["redis-server", "--logfile", "/var/log/redis/redis.log"]
# my-entrypoint.sh
#!/bin/bash

mkdir -p /var/log/redis

chown -R redis:redis /var/log/redis

exec docker-entrypoint.sh "$@"
# MariaDB
FROM mariadb:10.11-jammy

COPY my-entrypoint.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/my-entrypoint.sh

RUN sed -i \
    -e 's|^\(#*\)\(log_error\s*=\s*\).*|\2/var/log/mysql/error.log|' \
    /etc/mysql/mariadb.conf.d/50-server.cnf

ENTRYPOINT ["my-entrypoint.sh"]

CMD ["mariadbd"]
# my-entrypoint.sh
#!/bin/bash

mkdir -p /var/log/mysql

chown -R mysql:mysql /var/log/mysql

exec docker-entrypoint.sh "$@"

When I delete both of the log directories on the host, the one for MariaDB gets created, and the permissions are set to the mariadb user (999). Logs are written correctly. Redis does not create the directory, and even when I manually create it on the host and run chown -R 999:999 on it, Redis does not write logs there.

debian@vps-13995eb5:~$ ls -l /var/log/stack/redis
total 0
debian@vps-13995eb5:~$ ls -l /var/log/stack
total 20
drwxr-xr-x 2 root root            4096 Jul 24 07:00 apache
drwxr-xr-x 2 root root            4096 Jul 21 01:00 cron
drwxr-xr-x 2  999 systemd-journal 4096 Jul 24 10:22 mariadb
drwxr-xr-x 2 root root            4096 Jul 24 06:40 php
drwxr-xr-x 2  999 systemd-journal 4096 Jul 24 11:15 redis
debian@vps-13995eb5:~$ docker logs redis
debian@vps-13995eb5:~$ docker exec -it redis touch /var/log/redis/test
touch: cannot touch '/var/log/redis/test': No such file or directory
debian@vps-13995eb5:~$ docker exec -it redis ls -l /var/log/
total 88
-rw-r--r-- 1 root  root   3632 Jul 23 09:17 alternatives.log
drwxr-xr-x 1 root  root   4096 Jul 23 09:17 apt
-rw-rw---- 1 root  utmp      0 Jul 22 02:00 btmp
-rw-r--r-- 1 root  root  74600 Jul 23 09:17 dpkg.log
-rw-r--r-- 1 root  root      0 Jul 22 02:00 faillog
-rw-rw-r-- 1 root  utmp      0 Jul 22 02:00 lastlog
drwxr-xr-x 0 redis redis     0 Jul 24 13:03 redis
-rw-rw-r-- 1 root  utmp      0 Jul 22 02:00 wtmp
debian@vps-13995eb5:~$ docker top redis
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
999                 513499              513474              0                   11:02               ?                   00:00:02            redis-server *:6379

Any ideas on how to manually fix this issue, and ideally make the Redis container behave like the MariaDB container?

@LaurentGoderre
Copy link
Contributor

I have not found any example of redis setting the logfile via command line like this. All the example set it in the config file

@krbob
Copy link
Author

krbob commented Jul 24, 2024

According to the Redis documentation:

You can also pass Redis configuration parameters using the command line directly.

When I remove the bind mount and this directory becomes an internal directory of the container, logging to the specified file works correctly. Besides, I think an issue has surfaced here:

debian@vps-13995eb5:~$ docker exec -it redis touch /var/log/redis/test
touch: cannot touch '/var/log/redis/test': No such file or directory

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

2 participants