此文含:
1.linux安装docker 及docker常用命令
2.docker安装基础应用mysql/redis/nacos
3.docker容器部署java应用
4.docker容器部署jenkins实现自动化部署
5.docker容器部署nginx
1.docker安装及常用命令
(1)linux中安装docker:
https://blog.csdn.net/PyongSen/article/details/123053374
设置docker开机自启动: sudo systemctl start docker
(2)常用命令
进入docker容器: docker exec -it 容器名称 bash
退出容器且不关闭容器: Ctrl + p + q
查看容器日志: docker logs -f 容器名
复制文件到docker容器: docker cp 文件 容器名称:容器目录
更新容器自动重启:docker update --restart=always 容器ID(或者容器名)
2.docker安装基础应用mysql/redis/nacos
(1)docker安装mysql:
https://blog.csdn.net/hangejnu123/article/details/126853093
踩坑:my.cnf 这个配置文件不要修改名字!!!
修改配置前 chmod 666 允许修改
修改后 chmod 644 不允许修改(配置文件才会生效!mysql安全策略)
重启: docker restart mysql(容器名称)
(2)docker安装redis
https://blog.csdn.net/weixin_46152207/article/details/126846681
(3) docker安装nacos
https://blog.csdn.net/xtldcn/article/details/128867700
坑1:custom.properties 里数据库配置 不要写127.0.0.1 要具体ip地址!!!
坑2:增加9848的端口映射 不然(客户端2.x.x)服务注册不上去
启动容器:
docker run --name nacos -d \
-p 8848:8848 -p 9848:9848 \
--privileged=true --restart=always \
-e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone -e PREFER_HOST_MODE=hostname \
-v /usr/nacos/logs:/home/nacos/logs -v /usr/nacos/conf/application.properties:/home/nacos/conf/application.properties \
nacos/nacos-server:v2.1.1
3.docker部署java应用
https://blog.csdn.net/qq_39934154/article/details/121985650
思路:拉取openjdk:8镜像,打项目的jar包放在宿主机的自己文件夹下(/usr/cloud/file) 然后挂载到容器里,依托jdk8的镜像
执行下面命令直接运行容器进行部署
docker run -d --name file -p 9300:9300 \
-v /usr/cloud/file/:/usr/jar -v /usr/cloud/logs:/logs -v /etc/localtime:/etc/localtime \
--restart=always openjdk:8 \
java -jar /usr/jar/ruoyi-modules-file.jar
4.docker容器部署jenkins实现自动化部署
https://blog.csdn.net/lzc2644481789/article/details/124888223
docker pull jenkins/jenkins:2.344
(宿主机安装好 jdk/maven/git 容器会自带/nodejs 后 拉镜像、执行容器)
docker run -d --restart=always \
-p 8888:8080 -p 10241:50000 \
-e JAVA_OPTS=-Duser.timezone=Asia/Shanghai \
-v /usr/jenkins:/var/jenkins_home -v /usr/jdk1.8:/usr/local/jdk1.8 \
-v /usr/apache-maven-3.6.3:/usr/local/maven -v /usr/apache-maven-3.6.3/repository:/usr/apache-maven-3.6.3/repository \
-v /usr/node14:/usr/local/node14 -v /etc/localtime:/etc/localtime \
--env JAVA_OPTS="-Xms512m -Xmx1024m" \
--name jenkins -u 0 jenkins/jenkins:2.344
如果需要部署前端 则需要node 在jenkins容器里执行下面命令(根据自己从宿主机映射到容器后的npm/node的安装路径映射) 不然容器里会找不到npm node指令!!
ln -sv /usr/local/node14/bin/npm /usr/local/bin/npm
ln -sv /usr/local/node14/bin/node /usr/local/bin/node
思路:把jenkins打好的dist包 复制到nginx配置好的html目录下即可
构建后的脚本参考:
cp /usr/jenkins/workspace/cloud-auth/ruoyi-auth/target/ruoyi-auth.jar /usr/cloud/auth/ruoyi-auth.jar
docker stop auth
docker rm auth
docker run -d --name auth -p 9200:9200 \
-v /usr/cloud/auth/:/usr/jar -v /usr/cloud/logs/ruoyi-auth:/logs/ruoyi-auth -v /etc/localtime:/etc/localtime \
--restart=always openjdk:8 \
java -jar -Dspring.profiles.active=dev -Xms128M -Xmx256M /usr/jar/ruoyi-auth.jar
5.docker安装nginx
https://blog.csdn.net/BThinker/article/details/123507820
docker run \
-p 10000:80 -p 10001:81 -p 10002:82 -p 10003:83 \
--name nginx --restart=always \
-v /usr/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /usr/nginx/log:/var/log/nginx \
-v /usr/nginx/html:/usr/share/nginx/html \
-v /etc/localtime:/etc/localtime \
-d nginx:latest
做几个端口映射 后面增加端口有点麻烦、或者删除容器 重新执行命令运行容器
核心配置
server {
listen 82;
server_name localhost;
location / {
root /usr/share/nginx/html/city_cloud_admin;
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
6.docker安装minio
https://blog.csdn.net/qq_54673740/article/details/134731886
7.docker安装rocketmq
https://blog.csdn.net/ming19951224/article/details/109063041
控制台:不用docker装,因为不好配置登录,源码方式更改配置文件,然后打包 执行java -jar
https://blog.csdn.net/weixin_44121378/article/details/123104381