报错:chown: changing ownership of ‘varlibmysql‘: Permission denied

报错:chown: changing ownership of ‘varlibmysql‘: Permission denied,第1张

问题:
使用docker安装一个应用,在用docker启动一个mysql容器时,发现在容器一直启不来,查看日志发现:

[root@localhost media]# docker start 10ffc7586d0c
10ffc7586d0c
[root@localhost media]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                           NAMES
c633b6bc2d93        snipe/snipe-it      "/startup.sh"            4 minutes ago       Created                    443/tcp, 0.0.0.0:8082->80/tcp   snipe-it
10ffc7586d0c        mysql:5.6           "docker-entrypoint..."   7 minutes ago       Exited (1) 6 seconds ago                                   snipe-mysql
[root@localhost media]# docker logs 10ffc7586d0c
2022-04-06 08:20:09-05:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
find: '/var/lib/mysql/': Permission denied
chown: changing ownership of '/var/lib/mysql/': Permission denied
2022-04-06 08:24:29-05:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
find: '/var/lib/mysql/': Permission denied
chown: changing ownership of '/var/lib/mysql/': Permission denied
2022-04-06 08:25:14-05:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
find: '/var/lib/mysql/': Permission denied
chown: changing ownership of '/var/lib/mysql/': Permission denied
2022-04-06 08:27:50-05:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
find: '/var/lib/mysql/': Permission denied
chown: changing ownership of '/var/lib/mysql/': Permission denied

分析:
错误中,出现permission denied,意思是没有权限,

解决:
赋予该容器权限,即docker 启动容器的时候添加 --privileged=true

[root@localhost media]# docker run \
> --name snipe-mysql \
> --privileged=true \
> -d \
> -e MYSQL_ROOT_PASSWORD="snipe" \
> -e MYSQL_DATABASE=snipe \
> -e MYSQL_USER=snipe \
> -e MYSQL_PASSWORD="snipe" \
> -e TZ=America/Chicago \
> -p 127.0.0.1:3306:3306 \
> -v /media/snipe-mysql:/var/lib/mysql \
> mysql:5.6 --sql-mode=""
Unable to find image 'mysql:5.6' locally
Trying to pull repository docker.io/library/mysql ... 
5.6: Pulling from docker.io/library/mysql
35b2232c987e: Pull complete 
fc55c00e48f2: Pull complete 
0030405130e3: Pull complete 
e1fef7f6a8d1: Pull complete 
1c76272398bb: Pull complete 
f57e698171b6: Pull complete 
f5b825b269c0: Pull complete 
dcb0af686073: Pull complete 
27bbfeb886d1: Pull complete 
6f70cc868145: Pull complete 
1f6637f4600d: Pull complete 
Digest: sha256:20575ecebe6216036d25dab5903808211f1e9ba63dc7825ac20cb975e34cfcae
Status: Downloaded newer image for docker.io/mysql:5.6
639526c3708bf038fa3a51af93c443614e7d0199bec30078e3dbe5b4a84d4a4c
[root@localhost media]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                           NAMES
639526c3708b        mysql:5.6           "docker-entrypoint..."   6 seconds ago       Up 5 seconds        127.0.0.1:3306->3306/tcp        snipe-mysql
c633b6bc2d93        snipe/snipe-it      "/startup.sh"            9 minutes ago       Created             443/tcp, 0.0.0.0:8082->80/tcp   snipe-it
[root@localhost media]# docker start 639526c3708b
639526c3708b
[root@localhost media]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
639526c3708b        mysql:5.6           "docker-entrypoint..."   28 seconds ago      Up 27 seconds       127.0.0.1:3306->3306/tcp   snipe-mysql
[root@localhost media]# 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/567698.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存