配置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. 伯克利套接字(BSD Socket)

    http://blog.csdn.net/blueman2012/article/details/6693605#socket.28.29 伯克利套接字(Berkeley sockets),也称为BS ...

  2. matlab基础向9:动画

    先定义坐标变量,确定范围,画出起始静态图,存进图形变量h.通过对坐标的变化,把新的坐标放进图形变量h,再实时刷新看起来就是动态的. 1.动态的sin曲线 X = -2*pi:0.1:2*pi; Y = ...

  3. Numpy | 08 切片和索引

    ndarray对象的内容可以通过索引或切片来访问和修改,与 Python 中 list 的切片操作一样. (1)ndarray 数组索引可以基于 0 - n 的下标进行: (2)切片对象可以通过内置的 ...

  4. [PHP] Laravel 5.5 使用备注

    laravel-5_5文档地址:https://laravelacademy.org/category/laravel-5_5 模板变量文档: https://laravelacademy.org/p ...

  5. luogu P2353 背单词

    二次联通门 : luogu P2353 背单词 一眼看过去, 卧槽,AC自动机板子题 写完后T成SB 卧槽10^6 做个篮子啊 重构思路... 恩..Hash + 莫队... 恶心啊.. 找xxy d ...

  6. mac 搭建Java Spring boot 环境(eclipse)

    安装 下载安装Springboot 安装完成后,创建项目 1. 2. 3. 完成创建!

  7. 在Eclipse打开css文件时,会自动调用文本编辑器打开,而不是在Eclipse中打开

    问题描述 在Eclipse中打开css文件时候,如下图,使用系统自带的文本编辑器打开 解决方案 点击Window下的Preference,找到File Associations,然后点击Add,将cs ...

  8. web程序设计关于我们

    项目名称 福大咸鱼市场 开发团队 项目板块 负责人 美工 黄鸿杰 后端 胡继文 前端 葛家灿 联系方式:1175204449@qq.com

  9. React 版本16.9.0 中配置路由以及路由传参

    我的脚手架版本如下: "dependencies": { "antd": "^3.21.4", "jquery": &q ...

  10. 《Maven实战》整理

    一.maven介绍 Maven是优秀的构建工具,能够帮我们自动化构建过程,从清理.编译.测试到生成报告,再到打包和部署. Maven能帮助我们标准化构建过程.在Maven之前,十个项目可能有十种构建方 ...