21 2023-09-17 21:22:17 mkdir -p /home/my-projects
22 2023-09-17 21:22:28 docker pull tomcat
23 2023-09-17 21:28:55 docker images tomcat
24 2023-09-17 21:32:07 docker run -d -p 8080:8080 -v /home/my-projects:/usr/local/tomcat/webapps –privileged=true –name my-tomcat tomcat
25 2023-09-17 21:32:22 docker ps
26 2023-09-17 21:35:17 docker exec -it 7d5ab8816d7b /bin/bash
27 2023-09-17 21:39:21 docker start 7d5ab8816d7b
28 2023-09-17 21:41:26 curl http://119.29.17.67:8080
29 2023-09-17 21:41:43 mkdir myweb
30 2023-09-17 21:41:56 /home/my-projects
31 2023-09-17 21:42:04 cd /home/my-projects
32 2023-09-17 21:42:13 mkdir myweb
33 2023-09-17 21:42:22 cd myweb/
34 2023-09-17 21:42:32 vi index.html
35 2023-09-17 21:48:23 docker pull mysql:5.7
36 2023-09-17 21:49:05 mkdir -p /mysql/data
37 2023-09-17 21:49:34 docker run -d -p 3306:3306 –name mysql-5.7 -e MYSQL_ROOT_PASSWORD=123456 -v /mysql/data:/var/lib/mysql mysql:5.7
38 2023-09-17 21:49:45 docker ps
39 2023-09-17 21:49:57 docker exec -it ddba7f4cf1f8 /bin/bash
40 2023-09-17 21:50:15 docker exec -it 51f2c96985fa /bin/bash
41 2023-09-18 15:21:31 his
42 2023-09-18 15:21:33 history
主从复制
docker run -p 3306:3306 –name mysql-master \
-v /mydata/mysql-master/log:/var/log/mysql \
-v /mydata/mysql-master/data:/var/lib/mysql \
-v /mydata/mysql-master/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7
主机
docker run -p 3306:3306 –name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
1
2
3
4
5
6
然后查看状态发现啥也没有
于是docker ps -a 看了下
发现启动秒退了
看了下报错日志
docker logs 383400070a6f
2020-05-26 06:03:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1de
bian10 started.
chown: changing ownership of ‘/var/lib/mysql/’: Permission denied
1
2
3
4
说是什么权限不够…
然后百度了下
于是,解决方法有这么三个:
1.在docker run中加入 –privileged=true 给容器加上特定权限
2.关闭selinux csdn
3.在selinux添加规则,修改挂载目录
于是命令变成了
docker run -p 3306:3306 –name mysql \
–privileged=true -v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
发现成功了。