Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use remote docker daemon? #2313

Closed
jiangyongbing24 opened this issue Feb 29, 2020 · 5 comments
Closed

How to use remote docker daemon? #2313

jiangyongbing24 opened this issue Feb 29, 2020 · 5 comments

Comments

@jiangyongbing24
Copy link

Environment:

  • Jib version: 1.4.13
  • Build tool: Maven
  • OS: maven app: win10,remote docker daemon: centos7

Description of the issue:
I want to use the remote docker daemon to pull and upload images. The dockerclient Property in the document is configured as a daemon into the local path. If I want to use a remote one, how do I configure it?

@chanseokoh
Copy link
Member

chanseokoh commented Mar 2, 2020

Hi @jiangyongbing24

You should be able to pass Docker-specific environment variables like DOCKER_HOST. See #1956 (comment) For example,

jib {
  dockerClient.environment = [ DOCKER_HOST: '...', DOCKER_TLS_VERIFY: '...' ]
}

I have no experience using a remote Docker engine. I wonder if this will help: https://gist.github.com/kekru/4e6d49b4290a4eebc7b597c07eaf61f2#set-env-var-linux-mac-windows I'm curious if this actually works well. Could you update here after trying it?

@chanseokoh
Copy link
Member

For Maven, it should be like

<dockerClient>
    <environment>
        <DOCKER_HOST>...</DOCKER_HOST>
    </environment>
</dockerClient>

See https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#dockerclient-object

@chanseokoh
Copy link
Member

This actually works.

  1. Run a Docker daemon in Docker; API exposed via port 2375
    $ docker run --rm -p2375:2375 --privileged -e DOCKER_TLS_CERTDIR= docker:19.03.3-dind
    
  2. Set DOCKER_HOST to localhost:2375.
    <dockerClient>
        <environment>
            <DOCKER_HOST>localhost:2375</DOCKER_HOST>
        </environment>
    </dockerClient>
  3. Build and push an image with Jib.
    $ mvn jib:dockerBuild
    ...
    [INFO] Built image to Docker daemon as francium25/test
    ...
    [INFO] BUILD SUCCESS
    
  4. Check the image.
    $ docker inspect francium25/test
    []
    Error: No such object: francium25/test
    $ DOCKER_HOST=localhost:2375 docker inspect francium25/test
    [                                                                                                                                                                                                    
        {                                                                                                                                                                                                
            "Id": "sha256:f174a058dbd3cc99a8996f7a6b654c7bbb0928e44d33ae0d6b027120a6e92e4b",                                                                                                             
    

@swang-harbin
Copy link

swang-harbin commented Sep 2, 2021

This is my pom.xml

<project>
    ...
    <properties>
        <!--指定 jib-maven-plugin 插件的版本  -->
        <jib-maven-plugin.version>3.1.4</jib-maven-plugin.version>
    </properties>
    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>${jib-maven-plugin.version}</version>
        <configuration>
            <!-- 以哪个镜像作为基本镜像 -->
            <from>
                <image>openjdk:8</image>
            </from>
            <!-- 将该模块部署到哪个仓库 -->
            <to>
                <image>docker.io/swanghub/flowable-test</image>
                <!-- 推荐使用 credHelper 或者将用户名和密码配置在 maven 的 settings.xml 中 -->
                <!--auth>
                        <username>username</username>
                        <password>password</password>
                </auth-->
                <credHelper>wincred</credHelper>
                <tags>
                    <tag>${project.version}</tag>
                    <tag>latest</tag>
                </tags>
            </to>
            <!-- 配置 Docker daemon -->
            <dockerClient>
                <executable>docker</executable>
                <environment>
                    <DOCKER_HOST>http://intelli.icu:2375</DOCKER_HOST>
                </environment>
            </dockerClient>
            <!-- 容器相关属性设置 -->
            <container>
                <!-- 要暴露的端口 -->
                <ports>
                    <port>8080</port>
                </ports>
                <!-- 修改镜像默认时间,否则会出现镜像内时区不正确 -->
                <creationTime>USE_CURRENT_TIMESTAMP</creationTime>
            </container>
            <!-- 允许使用 http 连接 -->
            <allowInsecureRegistries>true</allowInsecureRegistries>
        </configuration>
        <executions>
            <!-- 在执行 mvn deploy 的同时,将项目打包成 docker 镜像并推送到 docker 远程仓库 -->
            <execution>
                <id>push-docker-image-when-maven-deploy</id>
                <phase>deploy</phase>
                <goals>
                    <goal>build</goal>
                </goals>
            </execution>
            <!-- 在执行 mvn package 的同事,将项目打包成 docker 镜像并推动到 Docker daemon -->
            <execution>
                <id>run-docker-image-when-maven-package</id>
                <phase>package</phase>
                <goals>
                    <goal>dockerBuild</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    ...
</project>

When I run mvn package or jib dockerBuild, it show:

Build to Docker daemon failed, perhaps you should make sure Docker is installed and you have correct privileges to run it

I want to push the image of this java application to the remote docker daemon, and let it run remotely as a container. I don't want to install anything about docker locally.

When I installed the Docker-CLI,it can push the image to the remote docker daemon。Why spotify/dockerfile-maven and fabric8io/docker-maven-plugin don't need Docker-CLI?

@chanseokoh
Copy link
Member

@swang-harbin unfortunately for now, Jib requires executing a Docker client (the docker CLI) to communicate to a Docker engine (whether remote or local): #1997

I believe you are already aware of this, but you just need to download and unzip a Docker client (docker); no need for a Docker engine (dockerd). For the spotify and fabric8io plugins, I guess they are using some Docker client Java library instead of running docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants