简体   繁体   中英

Mount volumes for mysql container

I can initiate a docker container using a command like this...

[root@localhost ~]# sudo docker run -p 3396:3306  -d mysql:5.7

But when I mount a volume, it does not work. I get permission denied error as shown below.

[root@localhost ~]# sudo docker run -p 3397:3306 -v /tmp/mysql/:/var/lib/mysql -d mysql:5.7
Digest: sha256:96edf37370df96d2a4ee1715cc5c7820a0ec6286551a927981ed50f0273d9b43
8d651cc66508605249d2c2672a18446fcc56e310cb40f46c9ea62a43e1a1837f

[root@localhost ~]# docker logs 8d651cc66508605249d2c2672a18446fcc56e310cb40f46c9ea62a43e1a1837f
chown: cannot read directory '/var/lib/mysql/': Permission denied

How do I mount volumes? I am facing this problem of this server only. On the other servers, the above command works correctly.


I tried with -u option, but get a different error this time...

[root@localhost ~]# sudo docker run -p 3397:3306  -u 1000:50   -v /tmp/mysql/datadir3396d:/var/lib/mysql -d mysql:5.7
b0caf9c4aeaeff5aade67e21f297c02c7eb39740ad1d7327d3291d96f360f805
[root@localhost ~]# docker logs b0caf9c4aeaeff5aade67e21f297c02c7eb39740ad1d7327d3291d96f360f805
Initializing database
mysqld: Can't create directory '/var/lib/mysql/' (Errcode: 17 - File exists)
2017-09-01T05:03:02.344875Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-09-01T05:03:02.346703Z 0 [ERROR] Aborting

Execute

rm -rf /tmp/mysql

Then run below

sudo docker run -e MYSQL_ROOT_PASSWORD=root -p 3397:3306 -v /tmp/mysql/:/var/lib/mysql -d mysql:5.7

You need to provide the MYSQL_ROOT_PASSWORD environment variable with root password for it to work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM