Docker maven plugin ClientProtocolException (Windows 10 using Docker Toolbox)
Asked Answered
A

3

8

I am trying to build a docker image using the docker-maven-plugin (provided by spotify: https://github.com/spotify/docker-maven-plugin) but things aren't really working out. At first I got this exception:

org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375

I found out that I had to create an env. variable to fix this (https://github.com/spotify/docker-maven-plugin/issues/135):

set DOCKER_HOST=set DOCKER_HOST=tcp://192.168.99.100:2376

docker_host

So after setting that env. variable I keep getting this ClientProtocolException:

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.3.258:build (default-cli) on project docker_micro_maven: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException: The server failed to respond with a valid HTTP response

I have no idea how I could fix this, any input would be greatly appreciated.

Aurlie answered 15/1, 2016 at 16:19 Comment(0)
B
5

You have to configure virtualbox port forwarding with host listen on 2375 port :

> VBoxManage modifyvm "default" --natpf1 "guestssh,tcp,,2375,,2376"

guestssh is the name of port forwarding, you can choose the name.

if VBoxManage isn't recognise, you can replace it by full path :

"pathVirtualBox\VBoxManage.exe"

And after if you have an issue like "The server failed to respond with a valid HTTP response" copy the certs files from
"%USER%.docker\machines\certs"
to
"%USER%.docker"
cause docker-maven-plugin read this files in "%USER%.docker" (don't copy directory certs, just files).

I think we can override maven properties to replace port 2375 and certs path, but i don't still find it.

Bethanie answered 15/7, 2016 at 14:24 Comment(1)
Too bad I can't give this answer more upvotes. Had the port forwarding configured prior finding this answer, but was still struggling with "The server failed to respond with a valid HTTP response". After copying certificates as suggested in this answer, everything started working as expected. Big thanks!Uvula
M
3

fixed this by:

        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.13</version>
            <configuration>
                <imageName>yourImageName</imageName>
                <dockerDirectory>src/main/docker</dockerDirectory>
                <dockerHost>https://192.168.99.100:2376</dockerHost>
                <dockerCertPath>/Users/your_user/.docker/machine/machines/default</dockerCertPath>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>

Important are these two tags:

<dockerHost>https://192.168.99.100:2376</dockerHost>
<dockerCertPath>/Users/your_user/.docker/machine/machines/default</dockerCertPath>

I am using a dockerfile, which path you have to define with this tag:

<dockerDirectory>src/main/docker</dockerDirectory>  

Now you can build your jar and generate docker image via:

mvn package docker:build

Maimonides answered 12/1, 2017 at 19:23 Comment(0)
C
0

docker-machine env default

set DOCKER_HOST=tcp://192.168.99.100:2376
set DOCKER_MACHINE_NAME=default
set DOCKER_TLS_VERIFY=1
set DOCKER_TOOLBOX_INSTALL_PATH=C:\Program Files\Docker Toolbox
set DOCKER_CERT_PATH=C:\Users\panhl-a\.docker\machine\machines\default
Communist answered 5/7, 2017 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.