0

I am unable to access my php container either by host name or ip address when I am not connected to internet. However, as soon as I connect to internet I can access container through ip or host name. I am on linux debian stretch.

/etc/hosts

127.0.0.1 test.dkr

docker-compose.yml

version: '3.2'
services:
  web:
    container_name: lamp_web
    build:
      context: .
      dockerfile: ./images/php/Dockerfile
    image: lamp-php-apache:7.2
    ports:
      - "80:80"
      - "443:443"    
    volumes:
      - ./www/lamp:/var/www/
      - ./configs/php/lamp.ini:/usr/local/etc/php/lamp
      - ./logs/apache:/var/log/apache2/lamp
    tty: true
    stdin_open: true
    links:
      - database:mysql
    environment:
      - APACHE_SERVERADMIN=admin@localhost
      - APACHE_RUN_USER=www-data
      - APACHE_RUN_GROUP=www-data
      - APACHE_LOG_DIR=/var/log/apache2
      - APACHE_PID_FILE=/var/run/apache2.pid
      - APACHE_RUN_DIR=/var/run/apache2
      - APACHE_LOCK_DIR=/var/lock/apache2
      - XDEBUG_CONFIG=remote_host=host.docker.internal remote_port=9000 remote_enable=1
    networks:
        lamp:
          ipv4_address: 172.19.0.3
  database:
    container_name: lamp_mysql
    build:
      context: .
      dockerfile: ./images/mysql/Dockerfile
    image: lamp-mysql:5.7
    ports:
      - "3306:3306"
    volumes:
      - ./data/mysql:/var/lib/mysql
    networks:
      - lamp
networks:
  lamp:
    driver: bridge
    ipam:
      driver: default
      config:
          - subnet: 172.19.0.0/24
sakhunzai
  • 13,900
  • 23
  • 98
  • 159
  • Since are using a docker network, the localhost addition is not needed (the 127.0.0.1). When the services are up and running try `docker network inspect lamp`. Do both the services appear in the list as being on the 172.19.x network? – David J Eddy Jul 09 '19 at 12:22
  • Why did you change `/etc/hosts` with such route? – Pierre B. Jul 09 '19 at 12:49
  • @DavidJEddy yes both appear on the network 172.19.x . – sakhunzai Jul 09 '19 at 13:00
  • @PierreB. my /etc/hosts contains: 127.0.0.1 test.dkr – sakhunzai Jul 09 '19 at 13:02
  • I see that, but for what reason did you add this line? It may break `localhost` which supposedly point to this, and maybe cause your issue (or others). Maybe try to remove this. – Pierre B. Jul 09 '19 at 13:04
  • What is the output of 'traceroute 172.19.0.3`* and `telnet 172.19.0.3. 80`? My goal here is to find out how the request is being routed, and by what. *If on windows I think it is `tracert`. – David J Eddy Jul 09 '19 at 13:21
  • `traceroute 172.19.0.3 traceroute to 172.19.0.3 (172.19.0.3), 30 hops max, 60 byte packets 1 172.19.0.3 (172.19.0.3) 0.120 ms 0.037 ms 0.030 ms` – sakhunzai Jul 09 '19 at 14:21
  • https://stackoverflow.com/questions/49998099/dns-not-working-within-docker-containers-when-host-uses-dnsmasq-and-googles-dns fixed my issue – sakhunzai Jul 09 '19 at 17:36
  • Please update the Question with a solution for the next person. TY. – David J Eddy Jul 09 '19 at 19:26

0 Answers0