Docker Maven Plugin管理 Docker 容器

联合创作 · 2023-09-27 14:41

docker maven plugin 是个简单的可以管理Docker容器maven插件,这个插件将会根据你的配置,在构建时启动容器,构建结束时停止容器并删除,如果本地找不到镜像,Docker会自动去中央仓库下载。

简单示例:

<plugin>
    <groupId>com.ofbizian</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
        <images>
            <image>
                <name>busybox</name>
            </image>
        </images>
    </configuration>
    <executions>
        <execution>
            <id>start-docker</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
    </executions>
</plugin>

所有可能配置的完整示例:

<plugin>
    <groupId>com.ofbizian</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
        <dockerUrl>http://localhost:4243</dockerUrl>
        <images>
            <image>
                <name>dockerfile/redis</name>
                <containerConfig>
                    <![CDATA[
                    {"Hostname":"",
                        "PortSpecs":null,
                        "User":"",
                        "Tty":false,
                        "OpenStdin":false,
                        "StdinOnce":false,
                        "Memory":0,
                        "MemorySwap":0,
                        "CpuShares":0,
                        "AttachStdin":false,
                        "AttachStdout":false,
                        "AttachStderr":false,
                        "Env":null,
                        "Cmd":null,
                        "Dns":null,
                        "Volumes":null,
                        "VolumesFrom":"",
                        "Entrypoint":[

                        ],
                        "NetworkDisabled":false,
                        "Privileged":false,
                        "WorkingDir":"",
                        "Domainname":"",
                        "ExposedPorts":null,
                        "OnBuild":null}
                    ]]>
                </containerConfig>
                <hostConfig>
                    <![CDATA[
                    {"ContainerIDFile": null, "LxcConf": null, "Links": null, "PortBindings": {
                        "6379/tcp": [
                            {
                                "HostIp": "0.0.0.0",
                                "HostPort": "6379"
                            }
                        ]
                    }, "Privileged": false, "PublishAllPorts": false}
                    ]]>
                </hostConfig>
            </image>
            <image>
                <name>busybox</name>
            </image>
        </images>
    </configuration>
    <executions>
        <execution>
            <id>start-docker</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-docker</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>
浏览 10
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报