cancel
Showing results for 
Search instead for 
Did you mean: 
Evaldas_R
Mission Specialist
Mission Specialist
  • 1,996 Views

Podman volume mount /var/lib/mysql problem.

Jump to solution

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)

 

 

Labels (2)
1 Solution

Accepted Solutions
Evaldas_R
Mission Specialist
Mission Specialist
  • 1,759 Views

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 

Evaldas_R_1-1725575507394.png

Works fine zero problems whatsoever??

Evaldas_R_2-1725575554901.png

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

View solution in original post

17 Replies
Chetan_Tiwary_
Community Manager
Community Manager
  • 1,308 Views

@Evaldas_R Instead of bind volume , try using named volume.

Otherwise try sudo chown mysql:mysql /home/student/mysql

 

Evaldas_R
Mission Specialist
Mission Specialist
  • 1,292 Views

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!

Chetan_Tiwary_
Community Manager
Community Manager
  • 1,283 Views

@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.

Chetan_Tiwary__0-1725556353947.png

 

Evaldas_R
Mission Specialist
Mission Specialist
  • 1,274 Views

No problem:

In the container mysql user is 999:999

Evaldas_R_0-1725557426652.png

Granting permissions:

Evaldas_R_1-1725557538687.png

First lets ignore the mysqld directory and mount only on mysql:

As you can see the container is running fine

Evaldas_R_2-1725557665553.png

So lets remove it and create it again:

Evaldas_R_3-1725557799790.png

As you can see now it doesnt want to work.

Logs?:

Evaldas_R_4-1725557844990.png

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...

Evaldas_R_5-1725557921598.png

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.

Evaldas_R_6-1725558106123.png

I run the container it works fine but remember its first time its ran.

Evaldas_R_7-1725558193198.png

So I delete it and try again, no luck:

Evaldas_R_8-1725558275332.png

So I figured its maybe that symlink?

Evaldas_R_9-1725558321211.png

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:

Evaldas_R_10-1725558423418.png

Evaldas_R_11-1725558447925.png

The dumb thing I was talking about is to create the symlink myself

Evaldas_R_12-1725558588088.png

Okay its owned by linda maybe should podman unshare?

Evaldas_R_13-1725558647052.png

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:

Evaldas_R_14-1725558782313.png

Okaay so the link now forwards to that file to my idea now it probably should? work? hm?

Evaldas_R_15-1725558847796.png

 

Lets try deleting it and running it again:

Evaldas_R_16-1725558922227.png

 

Pff zero luck..

Logs?:

Evaldas_R_17-1725558961185.png

 

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!

 

 

Chetan_Tiwary_
Community Manager
Community Manager
  • 1,267 Views

@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:

Chetan_Tiwary__0-1725561147309.png

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.

Evaldas_R
Mission Specialist
Mission Specialist
  • 1,264 Views

I can confirm that its working with (registry.redhat.io/rhel8/mariadb-105)

Evaldas_R_0-1725562091663.png

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:

Evaldas_R_1-1725562213271.png

 

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 confusioon

 

Chetan_Tiwary_
Community Manager
Community Manager
  • 1,263 Views

I also tried the lab in RH134 and it did not give any such errors : 

Chetan_Tiwary__1-1725562518640.png

Chetan_Tiwary__2-1725562533823.png

Chetan_Tiwary__5-1725564195667.png

 

Chetan_Tiwary_
Community Manager
Community Manager
  • 1,252 Views

I tried to follow your steps and used ~/mysql directory and was able to reproduce the error :

Chetan_Tiwary__3-1725563747067.png

so I gave 775 permission to ~/mysql and then it worked 

Chetan_Tiwary__4-1725563879688.png

have you tried the same ? or use podman unshare chown uid:gid /home/linda/mysql 

Evaldas_R
Mission Specialist
Mission Specialist
  • 1,241 Views

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 I have/had problems with (docker.io/library/mysql:latest)

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:

Evaldas_R_1-1725565565471.png

Ran the container on root:

Evaldas_R_2-1725565652526.png

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

 

 

Join the discussion
You must log in to join this conversation.