Score:2

WSL2 Dockerized Nginx not available in browser, but ping respond

cn flag

I have a Windows 10 Home on my computer with WSL2. In WSL I run Docker with this docker-compose.yml file:

version: "3"
services:
  httpd:
    image: 'nginx:stable-alpine'
    ports:
      - '80:80'
    volumes:
      - ./:/var/www/html
      - ./.docker-config/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - php
      - mysql
    networks:
      - mynet

  php:
    build:
      context: ./.docker-config/dockerfiles
      dockerfile: php.dockerfile
    volumes:
      - ./:/var/www/html:delegated
    networks:
      - mynet

networks:
  mynet:
    driver: bridge

In ./.docker-config/nginx/nginx.conf I have this configuration:

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    root /var/www/html/public;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

I start my Docker containers with this command:

docker-compose up -d

I add my custom domain to the hosts file in Windows with WSL2 current IP address.

In a Power Shell I try to ping my domain and it's responding, so I think the hosts config is good.

But if I try to reach my domain in a browser, is't not responding. The error message is ERR_CONNECTION_TIMED_OUT.

The wierd part is yesterday it was worked, and nothing changed in config files. The computer (and of course the WSL2 and the Docker) was shutted down and booted up today.

Any idea what's happend here and how can I avoid this situation in the future?

UPDATE

I changed my network's name, restart docker and everything is work's fine. But I don't understand what's happend here. Still I waiting answer to understand the reason of this issue.

Thanks!

simon avatar
pl flag
Make sure that WSL IPs are not changed: `wsl hostname -I`. For me, my WSL2 instance suddenly started issuing IPs from `192.168.*.*` subnet instead of from `172.*.*.*`.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.