Tkwon123
Tkwon123

Reputation: 4090

How do use external_links to connect docker-compose to common service?

I currently am using a docker-compose to setup a series of microservices which I want to link to a common error logging service (created outside the compose).

I am creating the errorHandling service outside of the compose.

docker run -d --name errorHandler

Then I run the compose (summarized):

version: '2'
services:
  my-service:
    build: ../my-service
    external_links:
      - errorHandler

I am using the hostname alias ('errorHandler') within my application but can't seem to get them connected. How do I check to see if the service if even discovered within the compose network?

Upvotes: 3

Views: 4211

Answers (1)

BMitch
BMitch

Reputation: 263617

Rather than links, use a shared docker network. Place the "errorHandler" container on a network in Docker, using something like docker network create errorNet and docker network connect errorNet errorHandler. Then define that network in your compose file for "my-service" with:

version: '2'
networks:
  errorNet:
    external: true

services:
  my-service:
    build: ../my-service
    networks:
     - errorNet

This uses docker's internal DNS to connect containers together.

Upvotes: 6

Related Questions