Docker Community Forums

Share and learn in the Docker community.

/etc/hosts file is not updated, using docker-compose file

I need to connect my “mysql” databases to apache2 server as a microservice. I have update the “-link of the mysql container in the apache2 container”, my bad luck that is not reflected in the /etc/hosts of the apache2 server.

my docker-compose.yml file

version: '2'

services:
  mysql:
    image: 'mysql'
    environment:
      - MYSQL_USERNAME=root
      - MYSQL_ROOT_PASSWORD=xxxxxxx
    ports:
      - '3309:3306'
    volumes:
      - ./volume/mysql:/var/lib/mysql

  prestashop:
    image: 'riay.r/presta-apache'
    ports:
      - '25:25'
      - '8081:80'
      - '443:443'
    links:
      - 'mysql:database'
    volumes:
      - ./volume/html:/var/www/html
      - ./volume/apache2/sites-enabled:/etc/apache2/sites-enabled
    depends_on:
      - mysql

  phpmyadmin:
    image: 'registry.poornam.com:5000/phpmyadmin/phpmyadmin'
    ports:
      - '8080:80'
    environment:
      - MYSQL_USERNAME=root
      - MYSQL_ROOT_PASSWORD=xxxxxxxx
      - PMA_HOST=prestashop
    depends_on:
      - mysql
      - prestashop

In the prestashop container /etc/hosts not updated with the mysql ip and hostid or container id.

It seems this is related to your compose file version:

If you’re using a version 2 Compose file, no /etc/hosts entries will be created. This is not a bug. Version 2 files make use of Docker networking, which uses DNS instead of /etc/hosts to resolve hostnames.

Reference: https://github.com/docker/compose/issues/2038#issuecomment-230630646