redis
redis copied to clipboard
Unable to log to bind mount
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?