How to Create a Directory with Docker Compose?

0
7
Asked By CuriousCoder92 On

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

Answered By ContainerGuru On

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!

Answered By QueryMaster On

What exactly are you trying to mount there, by the way? It could help to clarify your goals and maybe suggest a better solution.

Answered By TechSavvyUser On

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.

Answered By HandyDockerDude On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.