1

Recently I come across a docker-compose file with the below content:

version: '3'
services:
  serviceA:
    image: someService
    hostname: local_serviceA

I know when calling different services amount the same network, we can refer to the service name. For example, we can use http://serviceA to call serviceA.

But what is the use of the hostname field. Can other containers call service A using local_serviceA.

I have read this post but don't really understand. Can anyone help? Thanks in advance.

HKIT
  • 628
  • 1
  • 8
  • 19
  • `Can other containers call service A using local_serviceA?` => [Did you try ?](https://gist.github.com/zeitounator/acea4500b0e9319f77e1929cf7e55afc) – Zeitounator Feb 05 '21 at 14:56
  • @Zeitounator, thanks a lot. yes, service_a, local_service_a can call service_b, local_service_b and vice versa. so do they serve the same functionality? if yes, why do we need hostname field? – HKIT Feb 06 '21 at 13:47
  • You don't need to define a hostname. It's just a possibility to change to a non default as an alias. Note that you can add much more hostname to the same container with the `aliases` option on a specific network. You are the only one knowing if using any of those possibility is relevant in your project context. – Zeitounator Feb 07 '21 at 07:50

0 Answers0