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.