docker下安装mysqld后执行service mysqld start或者systemctl start mysql时会发现操作无法完成,此时需要通过映射目录的方式实现。
具体现象:service mysqld status会输出如下日志
New main PID 3991 does not belong to service, and PID file is not owned by root
解决方法如下:
方法1:创建容器时添加映射参数
创建容器的时候增加-v /sys/fs/cgroup:/sys/fs/cgroup
方法2:修改现有容器增加映射参数
1)关闭docker
service docker stop
2)进入容器目录
cd /var/lib/docker/containers/容器id/
3)修改hostconfig.json
vi hostconfig.json,修改Binds后内容如下
"Binds": ["/sys/fs/cgroup:/sys/fs/cgroup"],
4)修改config.v2.json
vi config.v2.json,修改如下,添加MountPoints:
"MountPoints": {
"/sys/fs/cgroup": {
"Source": "/sys/fs/cgroup",
"Destination": "/sys/fs/cgroup",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/sys/fs/cgroup",
"Target": "/sys/fs/cgroup"
},
"SkipMountpointCreation": false
}
},
5)启动docker
service docker start