配置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版本)的更多相关文章

  1. SpringBoot项目部署初体验【Docker】

    前言 一个微服务项目,小到几个模块,大到十几二十几个模块,每个模块都是单独的SpringBoot工程,这么多模块的部署,部署成本真的很高,而且每个服务的部署,都是手动部署,打成war或者jar ?,一 ...

  2. springboot项目部署到服务器上

    链接:https://blog.csdn.net/qq_22638399/article/details/81506448#commentsedit 链接2:https://blog.csdn.net ...

  3. Springboot 项目部署到服务器上

    项目部署到服务器上,有两种方式,一种 jar 包,一种 war 包 jar包 部署时,后续的域名配置,SSL证书等在nginx中配置 war包 部署时,后续的域名配置可以在tomcat中配置就好,修改 ...

  4. SpringBoot应用部署到Docker上(docker-io版本)

    配置TCP远程连接 为什么要配置这个呢,因为用到的docker-maven-plugin插件默认连接到localhost:2375上的docker.然而:1. 我们的Docker不在本地,执行打包命令 ...

  5. SpringBoot项目部署到服务器上,tomcat不启动该项目

    今天lz把项目重新传到服务器上后,重启tomcat遇到个问题,就是这个tomcat怎么都不启动这个项目,别的项目都没事,一番查找后发现问题所在. 我们先建个SpringBoot工程,重现一下问题: 写 ...

  6. 如何把springboot项目部署到tomcat上

    前言: 开始以为打包springboot项目为war包丢到tomcat上的webapps下面就可以访问controller层的路径了,可是调用接口却报404的错误,而打开8080的主页,不加路径却可以 ...

  7. React+SpringBoot项目部署

    静态资源访问配置 https://www.jianshu.com/p/b6e0a0df32ec https://segmentfault.com/q/1010000012240531/a-102000 ...

  8. windows上docker部署springboot多实例

    前提条件: 1.可以运行jar包的环境2.机器上已经安装了docker3.准备部署的springboot的jar包4.Dockerfile文件 准备Dockerfile FROM java:8 VOL ...

  9. ASP.NET CORE做的网站运行在docker上(不用dockerfile文件部署)

    按网上的做法用dockerfile文件是可以弄得出来的,http://www.docker.org.cn/article/119.html, 不过我想把网站文件放在外面硬盘目录,再映射进去,这样只要在 ...

随机推荐

  1. (1)树莓派3B+引脚

    http://shumeipai.nxez.com/raspberry-pi-pins-version-40

  2. SOS从内存转储中提取模块(EXE、DLL和其他二进制文件)

    假设有一种情况,您从客户那里得到一个内存转储,需要模块(DLL.EXE.OCX等)来进一步调试..(.NET模块可用于通过反向工程查看源代码.)我们可以使用windbg目录中的clr10\sos.dl ...

  3. [RN] React Native 使用 阿里巴巴 矢量图标库 iconfont

    React Native 使用 阿里巴巴 矢量图标库 iconfont 文接上文: React Native 使用精美图标库react-native-vector-icons 本文主要讲述 如何 使用 ...

  4. 退役III次后做题记录(扯淡)

    退役III次后做题记录(扯淡) CF607E Cross Sum 计算几何屎题 直接二分一下,算出每条线的位置然后算 注意相对位置这个不能先搞出坐标,直接算角度就行了,不然会卡精度/px flag:计 ...

  5. linux命令之------which命令/cp命令/Head及tail命令/grep命令/pwd命令/cd命令/df命令/mkdir命令/mount及umount命令/ls命令/history命令/ifconfig命令/ping命令/useradd命令/命令passwd/kill命令/su命令/clear命令/ssh命令/tar解压缩/远程拷贝scp

    which命令 1)    作用:搜索某个系统命令的位置. 2)    案例:查询vi命令路径:which vi cp命令 1)作用:用于复制文件或目录: 2)-a:此选项通常使用在复制目录时使用,它 ...

  6. k8s实现灰度发布

    灰度发布在实际生产部署中是经常被使用的方式,常规的方法是手动从前端LB(负载均衡)上将后端服务器摘掉,然后,停服务,最后上传代码,完成软连接更新.在使用CI/CD工具时,这个过程变得自动化了,我们只需 ...

  7. nginx.conf 配置解析之文件结构

    nginx.conf配置文件结构如下: ...... #主要定义nginx的全局配置 events{ #events(事件)块:主要配置网络连接相关 } http{ #http块:代理缓存和日志定义绝 ...

  8. js读取sqlserver数据库,输出至html

    代码: <!DOCTYPE html> <html> <head>   <meta charset="utf-8">   <m ...

  9. 【Beta】Phylab 测试报告

    PhyLab Beta 测试报告 测试中发现的bug Beta阶段新Bug Bug 可能原因 markdown生成的报告可能溢出显示框 表格过长,显示框未设置横向溢出 移动端实验区无法评论 移动端社区 ...

  10. S905系列的uboot分析

    Ubuntu18.04通过PL2303HX连接TTL 接线的连接 PL2303的3.3V悬空, TX接盒子RX, RX接盒子TX, GND接盒子GND 终端选择 系统自带pl2303的驱动, 可以通过 ...