0

I am using docker api to create containers, networks, services etc but my requirement is that I want my public facing container to communicate with another container running on the same network. For that to happen I can use container names as the hostname along with the port through which I am trying to connect my non-public facing container.

I am not able to find the name of the container via any service related api. I can definitely use docker-compose's link feature but I am trying to do that via a API. Can anyone help me with this?

Mudit Juneja
  • 165
  • 9
  • I'd set the full URL to the other service in an environment variable on the client container. In a Docker Compose context you'd know its hostname, but this is a setup that transplants well to local development, Kubernetes, _etc._ – David Maze Sep 13 '18 at 21:00
  • Yep, I used the service name:PORT in an environment variable and it worked. But both the containers should be lifted within the same network. – Mudit Juneja Sep 16 '18 at 00:15

1 Answers1

0

You can define the requirements for network in docker-compose.yml. See the example in https://docs.docker.com/compose/compose-file/#aliases. In your case, you may not need aliases, but the example in that section has an example.

By default, all the services defined in the compose file will be in one network.

If you want to do it by hand, https://docs.docker.com/engine/reference/commandline/network/ is the command you want. Use docker network create and multiple docker network connect for each of the containers.

Phani Kandula
  • 387
  • 2
  • 3
  • This is what I want but If I have ssh I can always use docker-compose.yml and start the app but I want to do the entire thing via calling the docker remote api. – Mudit Juneja Sep 16 '18 at 00:12