docker 证书安装 以及 idea打包build 到具体docker服务

#docker和idea建立安全连接
创建文件夹

	mkdir -p /usr/local/ca

	cd /usr/local/ca

	openssl genrsa -aes256 -out ca-key.pem 4096

记住输入的密码

	openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem

填写自定义参数

	Country Name (2 letter code) [XX]:CN
	State or Province Name (full name) []:Hangzhou, Zhejiang Province, People's Republic of China
	Locality Name (eg, city) [Default City]:XIACHENG
	Organization Name (eg, company) [Default Company Ltd]:WRETCHANT.COM
	Organizational Unit Name (eg, section) []:ONLINE ZUOZUO
	Common Name (eg, your name or your server's hostname) []:wretchant

生成server-key.pem

    openssl genrsa -out server-key.pem 4096


绑定IP或者域名
填写你的服务器外网IP 或者服务器外网域名
     
	openssl req -subj "/CN=182.61.59.216" -sha256 -new -key server-key.pem -out server.csr

	echo subjectAltName = IP:182.61.59.216,IP:0.0.0.0 >> extfile.cnf
	
生成ca-key

	echo extendedKeyUsage = serverAuth >> extfile.cnf

	openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem \-CAcreateserial -out server-cert.pem -extfile extfile.cnf

	openssl genrsa -out key.pem 4096

	openssl req -subj '/CN=client' -new -key key.pem -out client.csr

	echo extendedKeyUsage = clientAuth >> extfile.cnf
	
生成cert.pem

	openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem \-CAcreateserial -out cert.pem -extfile extfile.cnf

密钥赋权

	chmod -v 0400 ca-key.pem key.pem server-key.pem

	chmod -v 0444 ca.pem server-cert.pem cert.pem
	
辅助密钥到docker目录下

	cp server-*.pem  /etc/docker/

	cp ca.pem /etc/docker/
	
修改docker参数
	
    vi /lib/systemd/system/docker.service

把ExecStart 的值设置为如下

	/usr/bin/dockerd --tlsverify --tlscacert=/etc/docker/ca.pem --tlscert=/etc/docker/server-cert.pem --tlskey=/etc/docker/server-key.pem -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock

重启docker

	systemctl daemon-reload
	systemctl restart docker 
	service docker restart
	
拷贝文件到本地目录

    cd /usr/local/ca

	ca.pem
	cert.pem
	key.pem

然后idea连接

    ├──file                                      
        └── settings
            └── Build, Execution, Deployment
                └── Docker         
                    └── Engine api url: https://182.61.59.216:2376    远程docker地址         
                    └── Certificates folder: C:/xx/xx/key             证书文件夹

pom 分配具体发包服务器

<profiles>
        <profile>
            <id>test</id>
            <!--默认激活当前配置-->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profiles.active>test</profiles.active>
                <!-- Docker 配置 -->
                <docker.dockerHost>http://172.16.90.125:2375</docker.dockerHost>
                <docker.image.version>1.0.0</docker.image.version>
            </properties>
        </profile>
        <profile>
            <id>pro</id>
            <properties>
                <profiles.active>pro</profiles.active>
                <!-- Docker 配置 -->
                <docker.dockerHost>https://192.168.137.3:2376</docker.dockerHost>
                <docker.image.version>1.0.0</docker.image.version>
            </properties>
        </profile>
 </profiles>

docker pom 打包插件

<plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.2.2</version>

                <configuration>
                    <!-- 镜像名称  guoweixin/exam-->
                    <imageName>${project.artifactId}</imageName>
                    <!--指定标签-->
                    <imageTags>
                        <imageTag>latest</imageTag>
                    </imageTags>
                    <!-- 基础镜像jdk 1.8-->
                    <baseImage>java</baseImage>
                    <!-- 制作者提供本人信息 -->
                    <maintainer>wangchao wangchao@aliyun.com</maintainer>
                    <!--切换到/ROOT目录 -->
                    <workdir>/ROOT</workdir>
                    <cmd>["java", "-version"]</cmd>
                    <entryPoint>["java", "-jar", "${project.build.finalName}.jar"]</entryPoint>
                    <!-- 指定 Dockerfile 路径
                      <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
                   -->
                    <!--指定远程 docker api地址-->
                    <dockerHost>${docker.dockerHost}</dockerHost>
                    <!--证书文件夹-->
                    <dockerCertPath>C:/xx/xx/key</dockerCertPath>
                    <!-- 这里是复制 jar 包到 docker 容器指定目录配置 -->
                    <resources>
                        <resource>
                            <targetPath>/ROOT</targetPath>
                            <!--用于指定需要复制的根目录,${project.build.directory}表示target目录-->
                            <directory>${project.build.directory}</directory>
                            <!--用于指定需要复制的文件。${project.build.finalName}.jar指的是打包后的jar包文件。-->
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>

完整pom 文件 根据自己的项目具体改造

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>ruoyi</artifactId>
        <groupId>com.ruoyi</groupId>
        <version>3.1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <artifactId>red-food-market</artifactId>

    <description>
        web服务入口
    </description>
    <profiles>
        <profile>
            <id>test</id>
            <!--默认激活当前配置-->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profiles.active>test</profiles.active>
                <!-- Docker 配置 -->
                <docker.dockerHost>http://172.16.90.125:2375</docker.dockerHost>
                <docker.image.version>1.0.0</docker.image.version>
            </properties>
        </profile>
        <profile>
            <id>pro</id>
            <properties>
                <profiles.active>pro</profiles.active>
                <!-- Docker 配置 -->
                <docker.dockerHost>http://192.168.137.3:2375</docker.dockerHost>
                <docker.image.version>1.0.0</docker.image.version>
            </properties>
        </profile>
    </profiles>
    <dependencies>

        <!-- spring-boot-devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 表示依赖不会传递 -->
        </dependency>

        <!-- swagger2-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>

        <!--防止进入swagger页面报类型转换错误,排除2.9.2中的引用,手动增加1.5.21版本-->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.21</version>
        </dependency>

        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.21</version>
        </dependency>

        <!-- swagger2-UI-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>

        <!-- Mysql驱动包 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <!-- 核心模块-->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-framework</artifactId>
        </dependency>

        <!-- 定时任务-->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-quartz</artifactId>
        </dependency>

        <!-- 代码生成-->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-generator</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.1.RELEASE</version>
                <configuration>
                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.2.2</version>

                <configuration>
                    <!-- 镜像名称  guoweixin/exam-->
                    <imageName>${project.artifactId}</imageName>
                    <!--指定标签-->
                    <imageTags>
                        <imageTag>latest</imageTag>
                    </imageTags>
                    <!-- 基础镜像jdk 1.8-->
                    <baseImage>java</baseImage>
                    <!-- 制作者提供本人信息 -->
                    <maintainer>wangchao wangchao@aliyun.com</maintainer>
                    <!--切换到/ROOT目录 -->
                    <workdir>/ROOT</workdir>
                    <cmd>["java", "-version"]</cmd>
                    <entryPoint>["java", "-jar", "${project.build.finalName}.jar"]</entryPoint>
                    <!-- 指定 Dockerfile 路径
                      <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
                   -->
                    <!--指定远程 docker api地址-->
                    <dockerHost>${docker.dockerHost}</dockerHost>
                    <!--证书文件夹-->
                    <dockerCertPath>C:/xx/xx/key</dockerCertPath>
                    <!-- 这里是复制 jar 包到 docker 容器指定目录配置 -->
                    <resources>
                        <resource>
                            <targetPath>/ROOT</targetPath>
                            <!--用于指定需要复制的根目录,${project.build.directory}表示target目录-->
                            <directory>${project.build.directory}</directory>
                            <!--用于指定需要复制的文件。${project.build.finalName}.jar指的是打包后的jar包文件。-->
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>

    </build>

</project>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值