简体   繁体   中英

Cannot access Jenkins docker container from another docker container

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM