I'm having a tough time setting up a directory at /mnt/smth while using Docker Compose to create my container. When I try to create the directory through the Docker entry point, it runs as the MySQL user and doesn't have permission to create the directory. Is there a way to run a command as root in a Docker Compose setup? Also, I attempted to set up a volume with 'binlog:/mnt/db_replication', but that didn't work either. Any help would be appreciated! Here's a snippet of my Docker Compose configuration:
services:
mariadb:
image: mariadb:latest
container_name: mariadb-master
restart: unless-stopped
ports:
- "3306:3306"
environment:
MARIADB_ROOT_PASSWORD: root
volumes:
- ./replication.cnf:/etc/mysql/mariadb.conf.d/replication.cnf:ro
4 Answers
Remember, Docker containers only interact with what's inside them. If you want to create or modify files that the container needs, you need to mount them from the host. Just be cautious about giving root access, as that's not always safe!
What exactly are you trying to mount there, by the way? It could help to clarify your goals and maybe suggest a better solution.
It looks like you haven't set the PUID and GUID for the container. Try adding those to the environment section of your MariaDB service to match the MySQL user's PUID and GUID. Also, creating the folder on your host machine as an admin might simplify things. Just ensure the container has the right permissions to access it, and restart the container after making changes.
Instead of trying to create the directory inside the container, why not do it on your host machine first? Just run the mkdir and chown commands outside docker. If you set the permissions to match the MySQL UID (which is often 999), it should work smoothly when you map the volume.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically