java Maven 包 docker:build - 连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35549854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
maven package docker:build - connection refused
提问by KaffeeKaethe
I am trying to directly build a docker image with maven with mvn package docker:build
.
我正在尝试使用 .maven 直接构建一个 docker 镜像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:
Docker 正在运行并向docker ps
我展示我的容器,所以我假设一切都在正确运行。不过我确实收到以下错误:
[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 ->
[错误] 无法执行目标 com.spotify:docker-maven-plugin:0.2.3:build (default-cli) on project reservierung:捕获异常:java.util.concurrent.ExecutionException:com.spotify.docker.client。 shaded.javax.ws.rs.ProcessingException: o rg.apache.http.conn.HttpHostConnectException: 连接到 localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1 ] 失败:连接被拒绝:连接 ->
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.
我的第一种方法是,因为我在 Windows 上工作,所以我需要调用 docker-machine ip 地址而不是 localhost,但这也不起作用。我在这里有点不知所措,因为我认为这很简单,我做错了,但是当 docker(似乎)正常运行时,我找不到任何关于连接拒绝错误的信息。
I am sorry if this is trivial.
如果这是微不足道的,我很抱歉。
回答by jan.supol
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
在带有 Docker/Hyper-V 的 Windows 上,我用 com.spotify:docker-maven-plugin:1.0.0 发生了这种情况。在另一个论坛上有一个关于这个的讨论,他们建议打开
in docker Settings/General Tab. It worked for me.
在泊坞窗设置/常规选项卡中。它对我有用。
回答by u5487416
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>
回答by Bao Phan
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>
尝试运行 'docker-machine ls' 来检查 IP,如果它不是本地主机地址,则您的插件配置中将需要一个 dockerHost 标记。前任:<dockerHost>https://192.168.99.100:2376</dockerHost>
newest version of the plugin is 0.4.1 not 0.2.3
插件的最新版本是 0.4.1 而不是 0.2.3
回答by Alban
On MacOs, I just set the environment variables as shown by
在 MacOs 上,我只设置环境变量,如下所示
docker-machine env
docker-machine env
When running the build from an IDE, make sure these variables are properly set.
从 IDE 运行构建时,请确保正确设置这些变量。
回答by Le Danh
In ubuntu 16.04, I solved it with:
在 ubuntu 16.04 中,我解决了:
DOCKER_HOST=unix:///var/run/docker.sock mvn clean install
回答by Dada
update maven docker plugin to latest version 1.2.0. This solves the problem.
将 maven docker 插件更新到最新版本 1.2.0。这解决了问题。
回答by Vijay Nandwana
I fixed this by updating docker-maven-plugin
version to 1.4.13
.
我通过将docker-maven-plugin
版本更新到1.4.13
.
回答by Sandeep Kumar
If docker is running of Docker for Windows, then below things need to be completed: 1. Open Docker Settings 2. Enable the checkbox - Expose daemon on tcp://localhost:2375 without TLS
如果 docker 正在运行 Docker for Windows,则需要完成以下事情: 1. 打开 Docker 设置 2. 启用复选框 - 在没有 TLS 的情况下在 tcp://localhost:2375 上暴露守护进程
Normally, 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.
通常,docker 会为 docker 客户端打开端口 2376,但对于使用 TCP 的 2375 端口的旧版或其他应用程序连接。如果您使用的是 com.spotify,它也取决于版本。最新的 com.spotify 插件与最新的 docker 正常工作,否则需要定义一个变量,告诉插件从指定的环境变量中获取主机名。
To set the hostname manually for the docker set the variable into the environment variable list: DOCKER_HOST="tcp://127.0.00:2376"
要为 docker 手动设置主机名,请将变量设置到环境变量列表中:DOCKER_HOST="tcp://127.0.00:2376"
It will work for localhost, if docker is running on another machine then set the ip of the same machine.
它适用于本地主机,如果 docker 在另一台机器上运行,则设置同一台机器的 ip。
回答by U.V.
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)
在 Windows 7 64 上,安装 docker env 似乎有点棘手,因为它需要运行 linuxVM(更新以前的 vbox 安装问题) https://github.com/docker/machine/issues/3396)
Luckily in the docker quickstart terminal we can do:
幸运的是,在 docker quickstart 终端中,我们可以执行以下操作:
$ 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 :)
我们可以mvnw docker:build
在 cmd/intellij 终端中成功运行 :)
回答by realPK
Below change fixed my issue on OSX El Capitan, Docker Version 1.12.1 (build: 12133):
以下更改修复了我在 OSX El Capitan 上的问题,Docker 版本 1.12.1(版本:12133):
export DOCKER_HOST=unix:///var/run/docker.sock
Please restart docker if mvn package docker:build
still fails.
如果mvn package docker:build
仍然失败,请重新启动docker 。