SpringBoot应用部署到Docker上(docker-ce版本)
配置TCP远程连接(docker-maven-plugin插件连接的地址)
# 加上红色标识的部分
[root@localhost admin]# vim /lib/systemd/system/docker.service [Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket [Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=
RestartSec=
Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd .
# Both the old, and new location are accepted by systemd and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst= # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd .
# Both the old, and new name are accepted by systemd and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity # Comment TasksMax if your systemd version does not support it.
# Only systemd and above support this option.
TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes # kill only the docker process, not all processes in the cgroup
KillMode=process [Install]
WantedBy=multi-user.target
开放2375端口
# 开启防火墙端口
firewall-cmd --zone=public --add-port=/tcp --permanent
systemctl restart firewalld
配置私有仓库
配置daemon.json文件
[root@localhost admin]# vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.192.128:443"]
}

# 重启服务
systemctl daemon-reload
systemctl restart docker
然后下载registry镜像
[root@localhost admin]# docker pull registry
[root@localhost admin]# mkdir /usr/docker_registry_data
[root@localhost admin]# docker run -d -p : -v /usr/docker_registry_data:/var/lib/registry registry # 开启防火墙端口
firewall-cmd --zone=public --add-port=/tcp --permanent
systemctl restart firewalld
新建SpringBoot工程
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<!--Docker要求推送的映像名称以仓库的主机名和端口为前缀。例如,要推送my-image到registry.example.com,镜像需要标记为registry.example.com/my-image-->
<imageName>192.168.192.128:443/hello</imageName>
<!--基础镜像-->
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- copy the service's jar file from target into the root directory of the image -->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<forceTags>true</forceTags>
<imageTags>
<imageTag>latest</imageTag>
</imageTags>
</configuration>
</plugin>
</plugins>
</build>
打包(注意,要保证服务器的Registry容器开启)
SET DOCKER_HOST=tcp://192.168.192.128:2375
mvn clean package -Dmaven.test.skip=true docker:build -DpushImageTag

成功

现在回来看镜像

启动(后台启动加上-d)

访问

另一种方式:Dockerfile
在src/main下新建一个docker目录

Dockerfile内容
# 基础镜像
FROM java:
# 打包jar去向
ADD /hello-0.0.-SNAPSHOT.jar /app.jar
# 暴露端口
EXPOSE
# 启动命令
ENTRYPOINT ["java", "-jar", "/app.jar"]
pom文件修改如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<!--Docker要求推送的映像名称以注册表的主机名和端口为前缀。例如,要推送my-image到registry.example.com,镜像需要标记为registry.example.com/my-image-->
<imageName>192.168.192.128:443/hello-2</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<forceTags>true</forceTags>
<imageTags>
<imageTag>latest</imageTag>
</imageTags>
</configuration>
</plugin>
</plugins>
</build>
打包推送
SET DOCKER_HOST=tcp://192.168.192.128:2375
mvn clean package -Dmaven.test.skip=true docker:build -DpushImageTag
运行结果

查看镜像

SpringBoot应用部署到Docker上(docker-ce版本)的更多相关文章
- SpringBoot项目部署初体验【Docker】
前言 一个微服务项目,小到几个模块,大到十几二十几个模块,每个模块都是单独的SpringBoot工程,这么多模块的部署,部署成本真的很高,而且每个服务的部署,都是手动部署,打成war或者jar ?,一 ...
- springboot项目部署到服务器上
链接:https://blog.csdn.net/qq_22638399/article/details/81506448#commentsedit 链接2:https://blog.csdn.net ...
- Springboot 项目部署到服务器上
项目部署到服务器上,有两种方式,一种 jar 包,一种 war 包 jar包 部署时,后续的域名配置,SSL证书等在nginx中配置 war包 部署时,后续的域名配置可以在tomcat中配置就好,修改 ...
- SpringBoot应用部署到Docker上(docker-io版本)
配置TCP远程连接 为什么要配置这个呢,因为用到的docker-maven-plugin插件默认连接到localhost:2375上的docker.然而:1. 我们的Docker不在本地,执行打包命令 ...
- SpringBoot项目部署到服务器上,tomcat不启动该项目
今天lz把项目重新传到服务器上后,重启tomcat遇到个问题,就是这个tomcat怎么都不启动这个项目,别的项目都没事,一番查找后发现问题所在. 我们先建个SpringBoot工程,重现一下问题: 写 ...
- 如何把springboot项目部署到tomcat上
前言: 开始以为打包springboot项目为war包丢到tomcat上的webapps下面就可以访问controller层的路径了,可是调用接口却报404的错误,而打开8080的主页,不加路径却可以 ...
- React+SpringBoot项目部署
静态资源访问配置 https://www.jianshu.com/p/b6e0a0df32ec https://segmentfault.com/q/1010000012240531/a-102000 ...
- windows上docker部署springboot多实例
前提条件: 1.可以运行jar包的环境2.机器上已经安装了docker3.准备部署的springboot的jar包4.Dockerfile文件 准备Dockerfile FROM java:8 VOL ...
- ASP.NET CORE做的网站运行在docker上(不用dockerfile文件部署)
按网上的做法用dockerfile文件是可以弄得出来的,http://www.docker.org.cn/article/119.html, 不过我想把网站文件放在外面硬盘目录,再映射进去,这样只要在 ...
随机推荐
- 恕我直言,在座的各位根本不会写 Java!
恕我直言,在座的各位根本不会写 Java! java思维导图 作者:Lrwin,软件架构师. 导语 自 2013 年毕业后,今年已经是我工作的第 4 个年头了,总在做 Java 相关的工作,终于有时间 ...
- 洛谷 P1731 [NOI1999]生日蛋糕 题解
每日一题 day53 打卡 Analysis 观察一个蛋糕的俯视图,上表面的面积其实就是最下面那一层的底面积,所以在第一次搜索的时候加入这个底面积,之后就只用考虑侧面积就好啦. 就是每次枚举r和h,如 ...
- Tomcat8.x的安装与启动
Tomcat是企业网站的服务器,大多都用于中.小型网站开发和学习开发JSP应用程序中.笔者也是开始学习,下面介绍Tomcat8.x的安装步骤. 进入Tomcat官网,点击左边的download目录下的 ...
- [linux][c++]linux c++ 通过xcb库获取屏幕大小
linux c++ 通过xcb库获取屏幕大小 #include <stdio.h> #include <xcb/xcb.h> /** clang++ main.cpp -o m ...
- .htaccess tricks总结
目录 .htaccess tricks总结 一.什么是.htaccess 二.利用条件 三.利用方式 && tricks 1.将指定后缀名的文件当做php解析 2.php_value利 ...
- Ubuntu 16.04.4 LTS下安装OpenSSL
1.下载openssl,本次下载的版本是openssl-1.1.0l.tar.gz : 地址 https://www.openssl.org/source/openssl-1.1.0l.tar.gz ...
- 解决ffmpeg拉流转发频繁丢包问题max delay reached. need to consume packet
软件: 1.流媒体服务器EasyDarwin-windows-8.1.0-1901141151 2.ffmpeg-20181001-dcbd89e-win64-static 3.直播源:rtsp:// ...
- linux命令详解之du命令
du命令概述du命令作用是估计文件系统的磁盘已使用量,常用于查看文件或目录所占磁盘容量.du命令与df命令不同,df命令是统计磁盘使用情况,详见linux命令详解之df命令.du命令会直接到文件系统内 ...
- Django入门3 简单留言板项目案例及mysql驱动的安装配置
新建jangostart项目 使用manager.py新建app即单独的应用 创建一个message应用 manage.py@djangostart > startapp message 如果a ...
- 解决python3.7无法使用HTMLTestRunner.py生成html测试报告的问题2019.04
**一:首先下载这个HTMLTestRunner.py文件:链接: https://pan.baidu.com/s/1jQFsMYLM3ysY6shgRF40Kw 提取码: evq2二:把该文件放在p ...
