- 创建网络
docker network create hxa-network
2.创建mysql
docker run -d --name hxa_mysql \
-p 3306:3306 \
-v /home/hxa_mysql/mysql_files:/var/lib/mysql-files \
-v /home/hxa_mysql/conf:/etc/mysql \
-v /home/hxa_mysql/data:/var/lib/mysql \
-v /home/hxa_mysql/log:/var/log/mysql \
--network hxa-network \
--restart=always
-e MYSQL_ROOT_PASSWORD=123456 mysql:5.7 \
--character-set-server=utf8
允许远程连接 (不用也行)
# 进入mysql容器
docker exec -it hxa_mysql bash
# -u后接账户 -p接密码
mysql -uroot -p123456
# 外网范围授权
grant all privileges on *.* to root@'%' identified by "password";
# 刷新权限
flush privileges;
# 一定要更新密码,否则Navicat连接报1045错误
alter user 'root'@'%' identified with mysql_native_password by '123456';
# 刷新权限
flush privileges;
3.构建镜像
docker build -t hxa-test . --network=host
4.运行项目(没运行起来,系统内核版本太低)
docker run -d -p 80:80 \
-v /home/hxa-gouwu:/Project/test \
--network hxa-network \
--restart=always \
--name hxa_tt hxa_sp
升级系统内核版本(参考:Index of /elrepo/kernel/el7/x86_64/RPMS,CentOS 7.9 升级内核 kernel-ml-5.6.14版本的方法_云其它_脚本之家 (jb51.net)):
# 下载
wget http://193.49.22.109/elrepo/kernel/el7/x86_64/RPMS/kernel-ml-5.6.14-1.el7.elrepo.x86_64.rpm
wget http://193.49.22.109/elrepo/kernel/el7/x86_64/RPMS/kernel-ml-devel-5.6.14-1.el7.elrepo.x86_64.rpm
# 安装
rpm -ivh kernel-ml-5.6.14-1.el7.elrepo.x86_64.rpm
rpm -ivh kernel-ml-devel-5.6.14-1.el7.elrepo.x86_64.rpm
# 查看当前内核
cat /boot/grub2/grub.cfg |grep ^menuentry
# 设置启动内核
grub2-set-default 0 或 grub2-set-default 'CentOS Linux (5.6.14-1.el7.elrepo.x86_64) 7 (Core)'
# 重新生成配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg
升级成功后重装docker,构建镜像失败(利用另一台虚拟机构建镜像好镜像后导入到服务器)
# 导出
docker save -o tt.tar hxa-test
# 导入
docker load < tt.tar
5. 启动
docker run -itd --name hxa_gouwu -p 80:80 --network hxa-network hxa-test bash
6.访问
成功!!!!!!!!!!!!!!!!!!!!!!!!