Getting permission denied exception on mac while creating mysql container

~ docker run -v /opt/datadir:/var/lib/mysql mysql

2024-03-23 17:06:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.3.0-1.el8 started.

chown: changing ownership of ‘/var/lib/mysql/’: Permission denied

chown: changing ownership of ‘/var/lib/mysql’: Permission denied

What OS are you using? Is it one with SELinux enabled?

latest Mac OS Sanoma .I have checked command on terminal

~ sestatus

zsh: command not found: sestatus

~

Since this is more or less a BSD flavor of Unix, no selinux then. But I’m guessing that either /opt/datadir doesn’t exist on the Mac, or it does not belong to the mysql user. I did the following, and I get no error:

# I have a mysql user on my Mac via brew
sudo mkdir /opt/datadir
sudo chmod mysql:mysql /opt/datadir

# Try starting a container
docker run -d  -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -v /opt/datadir:/var/lib/mysql  --name test-mysql mysql

This works w/o error. So I’m guess that you need to create the /opt/datadir directory with appropriate ownership, and this will work.

Actually, wrong on the above: using colima (a Docker Desktop for Mac clone), -v was bound not to the Mac, but to colima’s virtual system’s file system. My local copy of /opt/datadir is untouched. On colima’s system, the directory is created and is populated by mysql’s binary files.

But if you’re using DD4M, you may need to do the steps I suggest above. See what -v does in that case for you.

Last login: Tue Mar 26 09:11:20 on ttys000

~ sudo chmod mysql:mysql /opt/datadir

Password:

chmod: Invalid file mode: mysql:mysql

sorry… wrong command. sudo chown mysql:mysql /opt/datadir