I defined a container in a docker-compose file. I want to access a non-docker server name (say database.xyz) inside the container as the dns name mydb.
How to define that in the compose file?
I defined a container in a docker-compose file. I want to access a non-docker server name (say database.xyz) inside the container as the dns name mydb.
How to define that in the compose file?
You can add an extra_hosts
section:
extra_hosts:
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
Documentation on this can be found at: https://docs.docker.com/compose/compose-file/#extra_hosts
You can use aliases.
Here is the example.
version: '3.4'
networks:
user_network:
driver: bridge
services:
listener:
image: asleea/test
command: nc -vlkp 10000
networks:
user_network:
aliases:
- listener_alias
client:
image: asleea/test
command: nc listener_alias 10000
depends_on:
- listener
networks:
user_network:
aliases:
- client_alias