Reputation: 301
I am trying to directly build a docker image with maven with mvn package docker:build
.
Docker is running and docker ps
shows me my containers, so I assume that everything is running correctly. I do get the following error though:
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.2.3:build (default-cli) on project reservierung: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: o rg.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect ->
My first approach was that since I am working on windows I need to call the docker-machine ip address instead of localhost, but that also didn't work. I am kind of at a loss here, because I assume that it's something simple that I am doing wrong, but I cannot find anything about the connection refused error when docker is (seemingly) running properly.
I am sorry if this is trivial.
Upvotes: 23
Views: 33814
Reputation: 2634
I fixed this by updating the docker-maven-plugin
dependency version.
Upvotes: 0
Reputation: 702
If docker is running of Docker for Windows, then below things need to be completed:
tcp://localhost:2375
without TLSNormally, docker opens up port 2376
for docker client but for legacy or other application connect using 2375
port using TCP.
If you are using com.spotify it depends upon version also. The latest com.spotify plugin with latest docker working correctly else need to define a variable that tells the plugin to get the hostname from specified environment variable.
To set the hostname manually for the docker set the variable into the environment variable list:
DOCKER_HOST="tcp://127.0.0.0:2376"
It will work for localhost, if docker is running on another machine then set the ip of the same machine.
Upvotes: 2
Reputation: 1
I was struggling with the same kind of error, and this is how I got rid of it.
Error: Cannot create docker access object [Cannot extract API version from server https://192.168.99.100:2375 : Connect to 192.168.99.100:2375 [/192.168.99.100] failed: Connection refused: connect]
In my case, the problem was that maven was unable to connect to the docker daemon process to build the image, because of the wrong host address.
You can find the right host address of the docker daemon process, by command
docker-machine env
Output: export DOCKER_HOST="tcp://192.168.99.100:2376"
Now, we can add below line in pom.xml.
https://192.168.99.100:2376
And, we are good to go. Hope this would help.
Upvotes: 0
Reputation: 9
update maven docker plugin to latest version 1.2.0. This solves the problem.
Upvotes: 0
Reputation: 403
In ubuntu 16.04, I solved it with:
DOCKER_HOST=unix:///var/run/docker.sock mvn clean install
Upvotes: 1
Reputation: 2805
On Windows with Docker/Hyper-V this occurred to me with com.spotify:docker-maven-plugin:1.0.0. There is a discussion about this on another forum, where they advise to turn on
in docker Settings/General Tab. It worked for me.
Upvotes: 35
Reputation: 81
i solve the problem using this setting:
<configuration>
<imageName>10.10.8.175:5000/${artifactId}:${project.version}</imageName>
<dockerHost>https://192.168.99.100:2376</dockerHost>
<dockerCertPath>C:\Users\AtomView\.docker\machine\machines\default</dockerCertPath>
<dockerDirectory>src/main/resources/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>*.zip</include>
</resource>
</resources>
</configuration>
Upvotes: 8
Reputation: 2989
Below change fixed my issue on OSX El Capitan, Docker Version 1.12.1 (build: 12133):
export DOCKER_HOST=unix:///var/run/docker.sock
Please restart docker if mvn package docker:build
still fails.
Upvotes: 0
Reputation: 708
On windows 7 64 the docker env seems a bit tricky to install as it requires a linuxVM to run (update issues with previous vbox installation) https://github.com/docker/machine/issues/3396 )
Luckily in the docker quickstart terminal we can do:
$ docker-machine.exe env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:2376"
export DOCKER_CERT_PATH="C:\Users\uv\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env)
showing us what to put into the plugin configuration
<dockerHost>https://192.168.99.101:2376</dockerHost>
but only after using the advice found here:
Docker: An error occurred trying to connect
with the important part being:
Run FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd default') DO %i
we can run the mvnw docker:build
successfully in the cmd/intellij terminal :)
Upvotes: 0
Reputation: 1943
On MacOs, I just set the environment variables as shown by
docker-machine env
When running the build from an IDE, make sure these variables are properly set.
Upvotes: 2
Reputation: 41
Try to run 'docker-machine ls' to check for the IP, if it's not a localhost address, you will need a dockerHost tag in your plugin configuration.
ex: <dockerHost>https://192.168.99.100:2376</dockerHost>
newest version of the plugin is 0.4.1 not 0.2.3
Upvotes: 4