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, 不过我想把网站文件放在外面硬盘目录,再映射进去,这样只要在 ...
随机推荐
- 电脑按键混乱,好像被锁定了Alt键
在知乎上找到一篇文章,https://zhuanlan.zhihu.com/p/34835461 解决了我的问题,解决办法是按住左右两边的alt+shift+ctrl
- Arduino OV7670 live image over USB to PC
https://www.youtube.com/watch?v=L9DTW1ulsT0 https://www.youtube.com/watch?v=Dp3RMb0e1eA
- WinDbg常用命令系列---!findstack
简介 !findstack扩展查找所有包含指定的符号或模块的堆栈.此命令搜索线程调用堆栈中的特定符号,并显示匹配的线程. 使用形式 !findstack Symbol[DisplayLevel] !f ...
- Java算法考试笔记
1.快速构建排列树: void BackTrace(int t){//排列树 if(t<N){//如果没有到叶子结点 for(int i=t;i<N;i++){ swap(x,t,i); ...
- DISCO Presents Discovery Channel Code Contest 2020 Qual题解
传送门 \(A\) 咕咕 int x,y; int c[4]={0,300000,200000,100000}; int res; int main(){ cin>>x>>y; ...
- Spring域属性和代理模式
一.域属性 好处:大幅度减少Spring配置 坏处:依赖不能明确管理,可能会有多个bean同时符合注入规则.没有清晰的依赖关系. 1,byName 根据属性名自动装配.此选项将检查容器并根据名字查找 ...
- TensorFlow 报错 ValueError: Can't load save_path when it is None.
原因 : 模型还未生成出来 , 此时你去检测的生成完毕的模型 , 模型呢 ? 还没生成 . 模型还没生成就引用了为什么不报错 ? 解决办法 : 当前情况不要以为是你的程序有 bug , 而是你的模型还 ...
- JPA批量插入优化
遇到一个需求是excel数据导入,一次大概会批量插入几万的数据.写完一测奇慢无比. 于是开始打日志,分析代码,发现是插入数据库的时候耗时很长,发现是spring data jpa的原因. 翻看jpa的 ...
- eclipse无法访问sun.misc.Unsafe类的解决办法
参考:https://www.cnblogs.com/duanxz/p/6090442.html
- git 执行 git reset HEAD 报 Unstaged changes after reset
Unstaged changes after reset 解决的办法如下2中办法: 1. git add . git reset --hard 2. git stash git stash dro ...
