Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reach services with the URL in Docker-Compose

Im trying to setup an application environment with two different docker-compose.yml files. The first one creates services in the default network elastic-apm-stack_default. To reach the services of both docker-compose files I used the external command within the second docker-compose file. Both files look like this:

# elastic-apm-stack/docker-compose.yml
services: 
  apm-server:
    image: docker.elastic.co/apm/apm-server:6.2.4
    build: ./apm_server
    ports:
      - 8200:8200
    depends_on:
      - elasticsearch
      - kibana
  ...

# sockshop/docker-compose.yml
services:
  front-end:
    ...
    ...
    networks:
      - elastic-apm-stack_default
networks:
  elastic-apm-stack_default:
    external: true

Now the front-end service in the second file needs to send data to the apm-server service in the first file. Therefore, I used the url http://apm-server:8200 in the source code of the front-end service but i always get an connectionRefused error. If I define all services in a single docker-compose file it works but I want to separate the docker-compose files. Could anyone help me? :)

like image 760
Hector Lorenzo Avatar asked May 22 '18 17:05

Hector Lorenzo


People also ask

How do you communicate with Docker compose?

Create an external network with docker network create <network name> In each of your docker-compose. yml configure the default network to use your externally created network with the networks top-level key. You can use either the service name or container name to connect between containers.

What is links in Docker compose?

3. Docker Compose links. links instructs Docker to link containers over a network. When we link containers, Docker creates environment variables and adds containers to the known hosts list so they can discover each other.


1 Answers

Docker containers run in network 172.17.0.1
So, you may use url

http://172.17.0.1:8200

to get access to your apm-server container.

like image 152
Andriy Avatar answered Oct 24 '22 03:10

Andriy