Docker lnmp Domain name Resolution Scheme

problem description

in the process of development and testing, we often have to do all kinds of test domain names. How to manage domain name resolution elegantly through the lnmp environment established by docker-compose?

only consider docker-compose, not docker run.,docker run. You can specify dns=xxx, or set dns in the default configuration of docker.

start the dnsmasq service in docker-compose and specify a fixed ip, for all services. Set dns to ip, of dnsmasq in the php container
. But after docker-compose up, you can see that the container IP setting is normal, but the dns of the php container is still 127.0.0.11 by default.
is not 172.25.0.5

.

the key contents of docker-compose.yml are as follows:

related codes

version: "3"
services:
  dnsmasq:
    image: jpillora/dnsmasq:latest
    restart: always
    networks:
      dnmp_net:
        ipv4_address: 172.25.0.5
    ports:
      - "53:53"
      - "5380:8080"
    volumes:
      - ./dnsmasq/dnsmasq.conf:/etc/dnsmasq.conf:rw
    environment:
      - HTTP_USER = admin
      - HTTP_PASS = xxxxxx

  php72:
    build:
      context: .
      args:
        PHP_VERSION: ${PHP72_VERSION}
        PHP_XDEBUG: ${PHP72_XDEBUG}
        PHP_SWOOLE: ${PHP72_SWOOLE}
        PHP_REDIS: ${PHP72_REDIS}
        REPLACE_SOURCE_LIST: ${REPLACE_SOURCE_LIST}
    volumes:
      - ${SOURCE_DIR}:/var/www/html/:rw
      - ${PHP72_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro
      - ${PHP72_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw
    restart: always
    cap_add:
      - SYS_PTRACE
    networks:
      dnmp_net:
        ipv4_address: 172.25.0.11
    dns: 
      - 172.25.0.5

networks:
  dnmp_net:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 172.25.0.0/24

the environmental background of the problems and what methods you have tried

1. Enter the / etc/hosts
2 of the container modification container, the / etc/resolv.conf, of the container modification container points to the custom dns server
3, start the dnsmasq service in docker-compose, and specify a fixed ip, for all services. Set dns to ip of dnsmasq in the php container

how do you manage domain name resolution in docker test environment? Is there a more scientific posture 0.0

Nov.22,2021

do I have to use ip? The container_name of the container created by docker-compose is the host domain name. If you use link or depends_on, you can also set an alias as the host domain name. Setting ip, in the container is thankless

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3cd07-446d3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3cd07-446d3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?