RSSAmplifier

Matthew Boston · Jun 14, 2018

Today I Learned: Docker Compose Networks

0
Sign in to vote or save

Matthew Boston · MatthewBoston.com

The problem

I have 2 services, let’s call them foo-service and bar-service. They both live in their respective directories as siblings.

.
├── bar-service
│   ├── docker-compose.yml
│   └── src
└── foo-service
    ├── docker-compose.yml
    └── src

bar-service refers to foo-service’s network like so:

# bar-service/docker-compose.yml
networks:
  default:
    external:
      name: fooservice_default

The yak shave

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

The solution

As of docker-compose 1.21.0:

Dashes and underscores in project names are no longer stripped out.

This means that the docker-compose.yml file above for bar-service needs the network name for foo-service updated to add back in the stripped dashes.

# bar-service/docker-compose.yml
networks:
  default:
    external:
      name: foo-service_default

As of Docker Compose file format version 3.5, the network name can be explicitly defined as described in Specify custom networks.

# foo-service/docker-compose.yml
version: "3.5"
networks:
  default:
    name: fooservice

And the original external network configuration file for bar-service would now work, referencing the network of foo-service as fooservice_default.

Read the original on matthewboston.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.