3

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?

Tkwon123
  • 3,672
  • 2
  • 13
  • 13

1 Answers1

6

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.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • ah wonderful trick. as a side note, under my-service I had to specify '- default'. much appreciated for the help-- spent far too long on this yesterday. just curious, is external links generally frowned upon? I cant seem to think of a reason why i wouldnt always favor using networks – Tkwon123 Oct 31 '16 at 12:48
  • 1
    Linking containers became the deprecated solution after docker introduced networks. I've never had a need to use it. – BMitch Oct 31 '16 at 17:54