I have a problem with mounting a volume of mysql.
podman run -d --name mysql -e MYSQL_ROOT_PASSWORD=password -v /home/student/mysql:/var/lib/mysql:Z docker.io/library/mysql:latest
This is my command as soon as I run it, it creates files in /home/student/mysql and it works, as soon as I delete it and try to run it again I get in logs:
find: '/var/lib/mysql/mysql.sock': Permission denied
chown: cannot access '/var/lib/mysql/mysql.sock': Permission denied
In home/student/mysql is a sym link:
mysql.sock -> /var/run/mysqld/mysqld.sock
So to my idea I also mounted the /var/run/mysqld container directory to /home/student/mysqld
Command:
podman run -d --name mysql -e MYSQL_ROOT_PASSWORD=password -v /home/student/mysql:/var/lib/mysql:Z -v /home/student/mysqld:/var/run/mysqld:Z docker.io/library/mysql:latest
Then also I try to run it but with no luck the sym link "mysql.sock -> /var/run/mysqld/mysqld.sock" forwards in wrong place and I dont know how to edit it... tried creating the symlink myself no luck..as soon as container stops running mysqld.sock file dissapears. If I try to run the container first time (I delete the /home/student/mysql/mysql.sock therefore it runs just the first time as file is created) and try to create sym link to mysql.sock -> /home/student/mysqld/mysqld.sock I cannot podman unshare chown 999:999 the file nothing happens.
Im beating my head in the wall right now its so frustrating, am I missing something? (this is my first time facing symlinks in container volumes)
OKAAY going crazy about it its literally 1:30 am
Found the solution and its confusing (atleast for me)
Tried different things.. found out its selinux issue.
Just for funs I tried changing :Z to lower case :z
From : -v /home/linda/testfolder:/var/lib/mysql:Z
To: -v /home/linda/testfolder:/var/lib/mysql:z
Works fine zero problems whatsoever??
Can someone explain the difference between uppercase :Z and lowercase :z ? I didnt get any AVC messages when using :Z option and the selinux was definetly blocking access for container.
Im so relieved and finally can go to sleep haha
@Evaldas_R Instead of bind volume , try using named volume.
Otherwise try sudo chown mysql:mysql /home/student/mysql
Tried using named volume,
$ podman create volume mysql
$ podman run -d --name mysql -e MYSQL_ROOT_PASSWORD=password -v mysql:/var/lib/mysql docker.io/library/mysql:latest
This way it works fine the container can be removed and created on the same volume without any problems.
But I still am confused how can I bind the volume to my /home/student/mysql:Z etc... the problem is the symlink in mysql directory (mysql.sock -> /var/run/mysqld/mysqld.sock) it probably forwards to local machines /var/run/mysqld/mysqld.sock which is bad and is not allowed (probably) it should link to its own containers mysqld.sock socket.
I tried mounting the /var/run/mysqld directory where the socket file lives, I run the container the first time it works, of course the sym link doesnt change and when I delete the container and run/create it again it throws error (find: '/var/lib/mysql/mysql.sock': Permission denied) It seems for me that I need somehow to change the symlink or something so that it forwards to (mysql.sock -> /home/student/mysqld/mysqld.sock) I can delete the bad symlink and create a new one but I cant (podman unshare chown) the symlink but the permissions are 777? I create the link (mysql.sock -> /home/student/mysqld/mysqld.sock) and it still throws me the error. Im sooo confused as why its not working.
sudo podman unshare doesnt work as you can only use podman unshare on rootless.
Thanks for replying!
@Evaldas_R need more info on the same! please provide step by step screenshot of what you are doing and what are the files , permissions and ownership etc and what error you are getting.
No problem:
In the container mysql user is 999:999
Granting permissions:
First lets ignore the mysqld directory and mount only on mysql:
As you can see the container is running fine
So lets remove it and create it again:
As you can see now it doesnt want to work.
Logs?:
So I head to my mounted directory and I can see a bunch of files and that symlink:
The symlink forwards to (mysql.sock -> /var/run/mysqld/mysqld.sock) ? This is normal? maybe it links to my local machines directory? I dunno...
So I decided to also mount the /var/run/mysqld directory where the mysqld.sock files lives?
First I need to delete the mysql.sock file because it will never run.
I run the container it works fine but remember its first time its ran.
So I delete it and try again, no luck:
So I figured its maybe that symlink?
Soo next thing I tried and its probably dumb I dunno is to once more delete the mysql.sock file and run the container again of course it rans:
The dumb thing I was talking about is to create the symlink myself
Okay its owned by linda maybe should podman unshare?
Duhh nothing changed probably cause its a link
So I remove the original mysql.sock lin in mysql directory and move the one that I created:
Okaay so the link now forwards to that file to my idea now it probably should? work? hm?
Lets try deleting it and running it again:
Pff zero luck..
Logs?:
I hope its clearer now
I can see that for you its working (from the provided screenshot) but I am using the (docker.io/library/mysql:latest) image and not red.hats one and that I think is the problem?, I want to point out that I am learning for RHCSA and this task is from the book.. and hit this "wall" but I like hitting these "wall's" as you learn more from them and as far as I can probably see the loose brick in the wall is that I am using the (docker.io/library/mysql:latest) image? I am really not sure and I cannot really say that the task is bad in the book as its written by an experienced Linux trainer and I am a guy trying to learn so I should be wrong here?
Thanks for helping!
@Evaldas_R Many thanks for detailed information, You can see it is working from my side but I am not using the image that you are using:
Just for reproducing the error , could you please try the same in Red Hat training lab using the image that I am using. You will need to authenticate to redhat.registry.io.
Meanwhile I will try to dig in more regarding your error.
I can confirm that its working with (registry.redhat.io/rhel8/mariadb-105)
Tried deleting it and creating it again works flawlessly just as you should expect.
Just for curiosity I checked the contents of /home/linda/redhatmysql:/var/lib/mysql directory:
Aaand its absolutely different the mysql.sock file is directly in that directory and not in (/var/run/mysqld) like in (docker.io/library/mysql:latest) image..
Sooo the image is not good? maybe its for docker not podman? Its weird
I also tried the lab in RH134 and it did not give any such errors :
I tried to follow your steps and used ~/mysql directory and was able to reproduce the error :
so I gave 775 permission to ~/mysql and then it worked
have you tried the same ? or use podman unshare chown uid:gid /home/linda/mysql
Yes I tried a lot of things, I think you are using the redhats (registry.redhat.io/rhel8/mariadb-105) image which is good and works perfectly
Been fidling with it and found out something
So (docker.io/library/mysql:latest) It should be used on rootfull container (Its probably created for docker) sooo...
I created the folder /mysql for /var/lib/mysql:
Ran the container on root:
Had some problem thought to myself I should disable SELINUX and it works perfectly. So for conclusion I think the (docker.io/library/mysql:latest) image is for DOCKER as I think docker only runs containers on root etc..
So for Podman you really should use (registry.redhat.io/rhel8/mariadb-105) image as its made for podman, rootless support, selinux etc..
And for Docker you should use (docker.io/library/mysql:latest) as its made for docker, cant really comment alot about docker since never really dag into it
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.