1.安装jdk
yum -y install java-1.8.0-openjdk*
2.安装并启动mysql
mysql高版本驱动变了,最后还是安装5.6
docker pull mysql:5.6
docker run --name xgr-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql
开放端口:
firewall-cmd --add-port=3306/tcp
关闭防火墙:
systemctl stop firewalld
本机链接虚拟机出现docker mysql Client does not support 错误,原因是mysql没开放访问权限
docker exec -it 容器bash
见下图
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.09 sec)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.04 sec)
成功链接虚拟机
3.创建docker 目录,编写Dockerfile文件,上传jar 文件
FROM openjdk:-jdk-alpine
COPY tuia-0.0.-SNAPSHOT.jar app.jar
EXPOSE
ENTRYPOINT ["java","-jar","/app.jar","--spring.profiles.active=test"]
4.创建镜像
docker build -t spring-boot-docker-tuia:v1.0 .
5.查看镜像
docker images
6.运行镜像 docker run
7.进入容器
docker exec -it 18476f195357 bash