joesan
joesan

Reputation: 15435

Docker Compose Hostname DNS Lookup Fails

I have a simple Docker compose file as below:

version: '3'
services:
  server:
     build: ./server
     networks:
        - common
     ports:
        - "4840:4840"
     container_name: open62541_server
     hostname: open62541-server
  client:
    build: ./client
    depends_on:
       - server
    container_name: open62541_client
    networks:
        - common

networks:
    common:

When I run it, I get the following error:

Attaching to open62541_server, open62541_client
open62541_server | [2019-06-27 12:19:54.864 (UTC+0000)] info/network    TCP network layer listening on opc.tcp://open62541-server:4840/
open62541_client | [2019-06-27 12:19:55.590 (UTC+0000)] warn/network    DNS lookup of open62541-server failed with error Name or service not known
open62541_client exited with code 0

Even after specifying that the containers belong to a common network, why is that I get this error? Is there anything I'm missing?

Upvotes: 5

Views: 4577

Answers (2)

b0gusb
b0gusb

Reputation: 4731

You probably have a typo in the config file. hostname is open62541-server and container_name is open62541_server (with underscore). You should be able to connect to server with either the service name (i.e. server) or container_name (i.e. open62541_server)

Upvotes: 1

Jakub Bujny
Jakub Bujny

Reputation: 4628

You should use server (service name) as host to which you connect within docker-compose network instead of open62541-server as neither container_name nor hostname section in docker file affects docker-compose's internal DNS.

Upvotes: 3

Related Questions