[GH-ISSUE #418] Documentation: hostname YAML property must be defined when using Docker Compose #145

Closed
opened 2026-02-26 04:34:11 +03:00 by kerem · 2 comments
Owner

Originally created by @wget on GitHub (Jun 24, 2023).
Original GitHub issue: https://github.com/mageddo/dns-proxy-server/issues/418

What is expected

When deploying Dns Proxy Server to a bunch of Docker hosts, I realized that Docker Compose deployment for which no hostname was defined into the YAML file, that DPS cannot answer to the request even if the container name was the same.

Example:

name: wordpress-prod                    
services:                                   
  wordpress-prod-db:             
    image: mariadb:10.11       
                                       
    container_name: wordpress-prod-db
    hostname: wordpress-prod-db  
    environment:
      [...]
    volumes:                      
      - "/srv/my-server.com/data/db:/var/lib/mysql/"
    networks:                                                                                                                                                                                                                                                                                                               
      - wordpress-prod-network
    restart: always
    secrets:
      - [...]

networks:
  wordpress-prod-network:
    name: wordpress-prod-network

What is Happening

We thought that DPS could handle the Docker Container names without having to specify hostname into the Docker Compose YAML file. After some tests, it appears this is needed.

Changes (Optional)

Give an example with Docker Compose in the documentation and provide more explanation about the use of hostname.

Originally created by @wget on GitHub (Jun 24, 2023). Original GitHub issue: https://github.com/mageddo/dns-proxy-server/issues/418 ### What is expected When deploying Dns Proxy Server to a bunch of Docker hosts, I realized that Docker Compose deployment for which no `hostname` was defined into the YAML file, that DPS cannot answer to the request even if the container name was the same. Example: ``` name: wordpress-prod services: wordpress-prod-db: image: mariadb:10.11 container_name: wordpress-prod-db hostname: wordpress-prod-db environment: [...] volumes: - "/srv/my-server.com/data/db:/var/lib/mysql/" networks: - wordpress-prod-network restart: always secrets: - [...] networks: wordpress-prod-network: name: wordpress-prod-network ``` ### What is Happening We thought that DPS could handle the Docker Container names without having to specify `hostname` into the Docker Compose YAML file. After some tests, it appears this is needed. ### Changes (Optional) Give an example with Docker Compose in the documentation and provide more explanation about the use of `hostname`.
kerem 2026-02-26 04:34:11 +03:00
Author
Owner

@mageddo commented on GitHub (Jun 10, 2024):

Hey @wget , solve container using container hostname property or by it's container name are two individual features, they work separately. I agree a dedicated doc to explain they usage could help a lot. I tested all combinations on DPS 3.19.1-snapshot and all are looking great.

Case 1

name: wordpress-prod
services:
  wordpress-prod-db:
    image: nginx
    container_name: wordpress-prod-db
    hostname: wordpress-prod-db-1
    networks:
      - wordpress-prod-network
    restart: always

networks:
  wordpress-prod-network:
    name: wordpress-prod-network
$  dig wordpress-prod-db.docker @127.0.0.1 -p 5354 +noall +answer

wordpress-prod-db.docker. 30	IN	A	172.29.0.2

Case 2

name: wordpress-prod
services:
  wordpress-prod-db:
    image: nginx
    container_name: wordpress-prod-db
#    hostname: wordpress-prod-db-1
    networks:
      - wordpress-prod-network
    restart: always

networks:
  wordpress-prod-network:
    name: wordpress-prod-network
$  dig wordpress-prod-db.docker @127.0.0.1 -p 5354 +noall +answer

wordpress-prod-db.docker. 30	IN	A	172.29.0.2

Case 3

name: wordpress-prod
services:
  wordpress-prod-db:
    image: nginx
#    container_name: wordpress-prod-db
#    hostname: wordpress-prod-db-1
    networks:
      - wordpress-prod-network
    restart: always

networks:
  wordpress-prod-network:
    name: wordpress-prod-network
$ dig wordpress-prod-db.docker @127.0.0.1 -p 5354 +noall +answer
wordpress-prod-db.docker. 30	IN	A	172.29.0.2

Case 4

hostname: wordpress-prod-db-1 will work but be aware of some side effects, is better to set either the domain option or set a suffix domain at hostnamee.g. hostname: wordpress-prod-db-1.dev.

name: wordpress-prod
services:
  wordpress-prod-db:
    image: nginx
#    container_name: wordpress-prod-db
    hostname: wordpress-prod-db-1
    networks:
      - wordpress-prod-network
    restart: always

networks:
  wordpress-prod-network:
    name: wordpress-prod-network
$ dig wordpress-prod-db-1 @127.0.0.1 -p 5354 +noall +answer
wordpress-prod-db-1. 30	IN	A	172.29.0.2
<!-- gh-comment-id:2158425965 --> @mageddo commented on GitHub (Jun 10, 2024): Hey @wget , solve container using container `hostname` property or by it's container name are two individual features, they work separately. I agree a dedicated doc to explain they usage could help a lot. I tested all combinations on DPS 3.19.1-snapshot and all are looking great. ## Case 1 ```yaml name: wordpress-prod services: wordpress-prod-db: image: nginx container_name: wordpress-prod-db hostname: wordpress-prod-db-1 networks: - wordpress-prod-network restart: always networks: wordpress-prod-network: name: wordpress-prod-network ``` ```bash $ dig wordpress-prod-db.docker @127.0.0.1 -p 5354 +noall +answer wordpress-prod-db.docker. 30 IN A 172.29.0.2 ``` ## Case 2 ```yaml name: wordpress-prod services: wordpress-prod-db: image: nginx container_name: wordpress-prod-db # hostname: wordpress-prod-db-1 networks: - wordpress-prod-network restart: always networks: wordpress-prod-network: name: wordpress-prod-network ``` ```bash $ dig wordpress-prod-db.docker @127.0.0.1 -p 5354 +noall +answer wordpress-prod-db.docker. 30 IN A 172.29.0.2 ``` ## Case 3 ```yaml name: wordpress-prod services: wordpress-prod-db: image: nginx # container_name: wordpress-prod-db # hostname: wordpress-prod-db-1 networks: - wordpress-prod-network restart: always networks: wordpress-prod-network: name: wordpress-prod-network ``` ```shell $ dig wordpress-prod-db.docker @127.0.0.1 -p 5354 +noall +answer wordpress-prod-db.docker. 30 IN A 172.29.0.2 ``` ## Case 4 `hostname: wordpress-prod-db-1` will work but be aware of some [side effects][1], is better to set either the `domain` option or set a suffix domain at `hostname`e.g. `hostname: wordpress-prod-db-1.dev`. ```yaml name: wordpress-prod services: wordpress-prod-db: image: nginx # container_name: wordpress-prod-db hostname: wordpress-prod-db-1 networks: - wordpress-prod-network restart: always networks: wordpress-prod-network: name: wordpress-prod-network ``` ```shell $ dig wordpress-prod-db-1 @127.0.0.1 -p 5354 +noall +answer wordpress-prod-db-1. 30 IN A 172.29.0.2 ``` [1]: https://github.com/mageddo/dns-proxy-server/issues/54#issuecomment-350389315
Author
Owner

@mageddo commented on GitHub (Jun 10, 2024):

A doc explaining how to solve docker containers from hostname was created as you suggested, contributions are welcome. Feel free to reopen it if there is any missing answer related to this issue.

Thanks for your contribution.

<!-- gh-comment-id:2158832834 --> @mageddo commented on GitHub (Jun 10, 2024): A [doc explaining how to solve docker containers from hostname][1] was created as you suggested, contributions are welcome. Feel free to reopen it if there is any missing answer related to this issue. Thanks for your contribution. [1]: https://mageddo.github.io/dns-proxy-server/3.19/en/2-features/docker-solving/
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/dns-proxy-server-mageddo#145
No description provided.