配置TCP远程连接

为什么要配置这个呢,因为用到的docker-maven-plugin插件默认连接到localhost:2375上的docker。然而:1. 我们的Docker不在本地,执行打包命令之前要设置一下环境变量【DOCKER_HOST=tcp://<host>:2375】;2. 默认Docker是关闭tcp远程连接的,所以我们要打开。

方法一:之前我们配置阿里云镜像的时候,新建了一个daemon.json文件,现在还要用到这个。就是配置【"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]

vim /etc/docker/daemon.json

# 添加如下内容,具体地址自己申请咯
{
"registry-mirrors": ["https://****.mirror.aliyuncs.com"],
"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]
} # 重启服务
systemctl daemon-reload
systemctl restart docker

然后开启防火墙端口 2375

[root@localhost admin]# firewall-cmd --zone=public --add-port=/tcp --permanent
success
[root@localhost admin]# systemctl restart firewalld

测试一下是否访问的通,可以在浏览器里访问,也可以在虚拟机里curl

如果是虚拟机

[root@localhost admin]# curl localhost:
{"message":"page not found"}

方法二

[root@localhost admin]# vim /lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target rhel-push-plugin.socket registries.service
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer [Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
--init-path=/usr/libexec/docker/docker-init-current \
--seccomp-profile=/etc/docker/seccomp.json \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=
LimitNPROC=
LimitCORE=infinity
TimeoutStartSec=
Restart=on-abnormal
KillMode=process [Install]
WantedBy=multi-user.target

将其中的ExecStart的最后新增下面红色所示

ExecStart=/usr/bin/dockerd-current \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
--init-path=/usr/libexec/docker/docker-init-current \
--seccomp-profile=/etc/docker/seccomp.json \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES \
-H unix:///var/run/docker.sock \
-H tcp://0.0.0.0:2375

然后重启服务,照样能满足需要

# 重启服务
systemctl daemon-reload
systemctl restart docker

配置私有仓库

先去配置一下文件

[root@localhost admin]# vim /etc/docker/daemon.json
# 在最后加上仓库配置
{
"registry-mirrors": ["https://****.mirror.aliyuncs.com","http://hub-mirror.c.163.com"],
"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"],
"insecure-registries":["192.168.192.128:443"]
}

记得重启服务

然后下载registry镜像,启动,我是把registry的5000容器端口映射到宿主443端口了,你们随意

[root@localhost admin]# docker pull registry
Using default tag: latest
Trying to pull repository docker.io/library/registry ...
latest: Pulling from docker.io/library/registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for docker.io/registry:latest
[root@localhost admin]# docker run -d -p 443:5000 registry
b56713ddca3f4b5903cc456002624a6cd6a6b3b79b8a542b873c461ed31b1b3b

记得把防火墙端口打开,参照上面

关于【docker 镜像删除后会把所有的数据和文件都删除,所以要把宿主机的本地目录挂载到registry容器内部的目录上,在删除registry容器后依旧能保证文件和数据不丢失】

无非先在宿主机上新建个目录,然后启动registry的时候,用-v参数做个映射。类似于下面:

进入registry容器内部,看它目录在哪

[root@localhost admin]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b56713ddca3f registry "/entrypoint.sh /e..." minutes ago Up minutes 0.0.0.0:->/tcp confident_
[root@localhost admin]# docker exec -it b56713ddca3f sh
/ # find / -name registry
/bin/registry
/etc/docker/registry
find: /proc/scsi: Permission denied
find: /sys/firmware: Permission denied
/var/lib/registry
/var/lib/registry/docker/registry

可以看到,挂载在 var/lib/registry 目录下,所以:

# 停止容器
[root@localhost admin]# docker stop b56713ddca3f
b56713ddca3f
# 删除容器
[root@localhost admin]# docker rm b56713ddca3f
b56713ddca3f # 新建宿主机目录
mkdir /usr/docker_registry_data
# 启动容器
docker run -d -p : -v /usr/docker_registry_data:/var/lib/registry registry

新建工程

在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</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>

然后build,先配置docker地址,然后执行build命令

SET DOCKER_HOST=tcp://192.168.192.128:2375
mvn clean package -Dmaven.test.skip=true docker:build -DpushImageTag

回到服务器,查看镜像

启动镜像

浏览器访问

以上第一次推送,会有一大堆东西输出,然而之后的推送就不会了,如下:

镜像:

你也可以进入容器内部,看看日志什么的。。。虽然我这个没有日志

[root@localhost admin]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d71e487f00a6 0c24558dd388 "java -jar /hello-..." minutes ago Exited () minutes ago nervous_noether [root@localhost admin]# docker start d71e487f00a6
d71e487f00a6
[root@localhost admin]# docker exec -it d71e487f00a6 bash
root@d71e487f00a6:/# ls
bin boot dev etc hello-0.0.-SNAPSHOT.jar home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@d71e487f00a6:/#

SpringBoot应用部署到Docker上(docker-io版本)的更多相关文章

  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-ce版本)

    配置TCP远程连接(docker-maven-plugin插件连接的地址) # 加上红色标识的部分[root@localhost admin]# vim /lib/systemd/system/doc ...

  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. Generative Adversarial Networks overview(4)

    Libo1575899134@outlook.com Libo (原创文章,转发请注明作者) 本文章主要介绍Gan的应用篇,3,主要介绍图像应用,4, 主要介绍文本以及医药化学其他领域应用 原理篇请看 ...

  2. CF1102D-Balanced Ternary String-(贪心)

    http://codeforces.com/problemset/problem/1102/D 题意: 有n个字符,只能为012,现要通过变换让012的数量相等,并且使字典序最小. 解题: 由样例可以 ...

  3. node.js – 服务器端的客户端证书验证,DEPTH_ZERO_SELF_SIGNED_CERT错误

    我正在使用节点0.10.26并尝试建立与客户端验证的https连接. 服务器代码: var https = require('https'); var fs = require('fs'); proc ...

  4. [教程]Ubuntu16.04安装texstudio

    [教程]Ubuntu16.04安装texstudio step 1 首先要下载texlive. 不会的戳这里 然后直接终端命令 sudo apt-get install texstudio step ...

  5. 验证码破解 | Selenium模拟登陆微博

    模拟登陆微博相对来说,并不难.验证码是常规的5个随机数字字母的组合,识别起来也比较容易.主要是用到许多Selenium中的知识,如定位标签.输入信息.点击等.如对Selenium的使用并不熟悉,请先移 ...

  6. type of的返回值有哪些

    typeof 10; // number typeof 'time'; //string typeof undefined; // undefined typeof null; // object t ...

  7. hive基础知识二

    1. Hive的分区表 1.1 hive的分区表的概念 在文件系统上建立文件夹,把表的数据放在不同文件夹下面,加快查询速度. 1.2 hive分区表的构建 创建一个分区字段的分区表 hive> ...

  8. js中的逗号运算符

    逗号运算符 逗号运算符是二元运算符,它的操作数可以是任意类型.它首先计算左操作数,然后计算右操作数,最后返回右操作数的值,用逗号运算符可以在一条语句中执行多个运算 作用: 1.在一条语句中从左到右执行 ...

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

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

  10. PTES渗透测试执行标准

    渗透测试注意事项: 1:测试一定要获得授权方才能进行,切勿进行恶意攻击 2:不要做傻事 3:在没有获得书面授权时,切勿攻击任何目标 4:考虑你的行为将会带来的后果 5:天网恢恢疏而不漏 渗透测试执行标 ...