无法从另一个Docker容器访问Jenkins Docker容器
我有两个当地的Docker容器:Jenkins和Bitbucket。我似乎无法从Bitbucket到Jenkins提出HTTP请求。但是,我可以从Jenkins到Bitbucket提出请求。
容器的运行方式:
bitbucket:
docker run -v bitbucketVolume:/var/atlassian/application-data/bitbucket --name="bitbucket" -d --add-host host.docker.internal:host-gateway -p 7990:7990 -p 7999:7999 atlassian/bitbucket-server
jenkins:
docker run --name=jenkins -d --add-host host.docker.internal:host-gateway -v jenkins_home:/var/jenkins_home -p 9080:8080 -p 50000:50000 jenkins/jenkins:latest
为简单性和演示目的,我将使用curl命令来体现这种行为。
从 jenkins到Bitbucket 的请求,将卷曲调用到Bitbucket容器时将获得预期的结果:
jenkins@c1f0ec99a73a:/$ curl -v host.docker.internal:7990
* Trying 172.17.0.1:7990...
* Connected to host.docker.internal (172.17.0.1) port 7990 (#0)
如果相反,从 bitbucket到Jenkins ,它将不会成功:
root@2a350f4d1ff4:/var/atlassian/application-data/bitbucket# curl -v host.docker.internal:8080
* Could not resolve host: host.docker.internal
* Closing connection 0
curl: (6) Could not resolve host: host.docker.internal
问题:我缺少哪种配置,无法从Bitbucket容器到Jenkins One?
I have two local docker containers: Jenkins, and Bitbucket. I cannot seem to make http requests from Bitbucket to Jenkins. However, I can make requests from Jenkins to Bitbucket.
The containers were ran as such:
Bitbucket:
docker run -v bitbucketVolume:/var/atlassian/application-data/bitbucket --name="bitbucket" -d --add-host host.docker.internal:host-gateway -p 7990:7990 -p 7999:7999 atlassian/bitbucket-server
Jenkins:
docker run --name=jenkins -d --add-host host.docker.internal:host-gateway -v jenkins_home:/var/jenkins_home -p 9080:8080 -p 50000:50000 jenkins/jenkins:latest
For simplicity and demonstration purposes I will use the curl command to exemplify the behaviour.
Making a request from Jenkins to Bitbucket, will get the expected result when invoking curl to the Bitbucket container:
jenkins@c1f0ec99a73a:/$ curl -v host.docker.internal:7990
* Trying 172.17.0.1:7990...
* Connected to host.docker.internal (172.17.0.1) port 7990 (#0)
If it's the other way around, from Bitbucket to Jenkins, It will not succeed:
root@2a350f4d1ff4:/var/atlassian/application-data/bitbucket# curl -v host.docker.internal:8080
* Could not resolve host: host.docker.internal
* Closing connection 0
curl: (6) Could not resolve host: host.docker.internal
Question: what configuration am I missing to be able to comunicate from the Bitbucket container to the Jenkins one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在通过host.docker.internal进行通信。
这意味着您将通过运行容器的主机从1个容器到另一个容器。
您为什么不直接从一个容器转到另一个容器,而无需提及主机。
这也更好,因为您会失去主机的依赖。docker.internal(并不总是在所有平台上使用)
从一个容器直接转到另一个容器,可以通过两种方式完成:
docker-compose
将所有容器规格放在1个Docker-compose中文件。然后,可以通过docker-compose文件中的服务名称连接到“其他”容器
使用IP-NETWORK
首先创建您自己的Docker网络,并具有第三个容器函数作为ProxyServer(Running Nginx)。
然后给每个容器一个IP地址,您可以通过IP连接。
You are communicating over host.docker.internal.
That means you are going from 1 container to the other via the Host which runs the container.
Why don't you go from one container to the other directly without mentioning the Host.
That's also better because you lose the dependency of host.docker.internal (which does not always work on all platforms)
Going from one container directly to another can be done in 2 ways:
docker-compose
Put all container specifications in 1 docker-compose file. Then the 'other' container can be connected to via their service name in the docker-compose file
use IP-network
First create your own docker network and have a third container function as a proxyserver (running Nginx).
Then give each container an IP address and you can connect via IP.