Home > Software engineering >  How do I reach a container through the host's hostname from another container?
How do I reach a container through the host's hostname from another container?

Time:03-18

I'm running docker 20.10 and docker-compose 1.29.2 on Centos 7.

I have two containers (bitbucket and jenkins) running on myhost using docker-compose. I'm using the default bridge network. The following are the hosts names and services:

host        : service/port   : container/host port mapping
myhost      : apache/80      : <na>
bitbucket   : bitbucket/7990 : 7990:7990
jenkins     : jenkins/8083   : 8083:8083
workstation : <na>           : <na>

From workstation, I get results from curl myhost:80 and I get results from curl myhost:7990.

From jenkins I get results from curl bitbucket:7990 and curl myhost:80 but the problem is I DO NOT from curl myhost:7990.

I need to be able to reach a submodule from jenkins that is in bitbucket, and I want the .gitmodules file to reference the same submodule URL: myhost:7990/scm/project/repo.

I don't have any special network configuration on myhost. I tried adding 7990 to the docker zone (firewall-cmd), but that did not help.

It seems like it is almost working. What is the problem and solution here?

Thank you!

CodePudding user response:

Try using the private IP of the container. If they are in the same network, it should work.

docker inspect <container ID> | grep -w -m1 "IPAddress"

<private IP>:7990/scm/project/repo

CodePudding user response:

What is the problem and solution here?

try by adding link in your docker-compose's service by which It will link two different containers from each other.

  • Links allow you to define extra aliases by which a service is reachable from another service.
  • Related