docksal / docksal

Unified, Docker 🐳 powered web development environments for macOS, Windows, and Linux
https://docksal.io
MIT License
691 stars 178 forks source link

docker in WSL2 is not expose to 192.168.64.100 (docksal.site) #1636

Open obriat opened 2 years ago

obriat commented 2 years ago

Description I use docksal with WIN10 + WSL2 + docker and the default domain (docksal.site or 192.168.64.100) is not reachable from the browser host, I had to switch to 127.0.0.1 + edit hosts file.

It's not working with Docker Desktop or docker runs directly from WSL.

I don't know if it's linked to my VPN (greedy VPN) or the fact HyperV V-Switch has no fixed IP.

Please give a workaround that insure that 192.168.64.100 is present and point to docker.

Problem/feature description...

Steps to reproduce the issue:

  1. Start docksal on a Win10 + WSL2 + docker
  2. Open on your browser https://your_project.docksal.site

Describe the results you received:

"Host could not be reach"

Describe the results you expected:

Access to the web site from the windows host.

Additional info:

Inside WSL, networking seems to work fine

curl -I http://myproject.docksal.site
HTTP/1.1 200 OK
...

ifconfig
...
lo:docksal: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.64.1  netmask 255.255.255.0
        loop  txqueuelen 1000  (Local Loopback)
...

Output of fin config:

fin config output ``` --------------------- COMPOSE_PROJECT_NAME_SAFE: my_project COMPOSE_FILE: /home/USER/.docksal/stacks/volumes-bind.yml /home/USER/.docksal/stacks/stack-default.yml /home/USER/projects/my_project/.docksal/docksal.yml ENV_FILE: /home/USER/projects/my_project/.docksal/docksal.env /home/USER/projects/my_project/.docksal/docksal-local.env PROJECT_ROOT: /home/USER/projects/my_project DOCROOT: web VIRTUAL_HOST: my_project.docksal.site VIRTUAL_HOST_ALIASES: *.my_project.docksal.site IP: 192.168.64.100 MYSQL: 192.168.64.100:33062 Docker Compose configuration --------------------- services: cli: build: context: /home/USER/projects/my_project/.docksal/services/cli dns: - 192.168.64.100 - 172.20.100.8 environment: BLACKFIRE_CLIENT_ID: null BLACKFIRE_CLIENT_TOKEN: null COMPOSER_ALLOW_XDEBUG: '0' COMPOSER_DEFAULT_VERSION: null COMPOSER_DISABLE_XDEBUG_WARN: '0' DOCROOT: web DRUSH_ALLOW_XDEBUG: '0' DRUSH_OPTIONS_URI: my_project.docksal.site GIT_USER_EMAIL: ***** GIT_USER_NAME: Olivier Briat HOST_GID: '1000' HOST_UID: '1000' MEMCACHED_HOST: memcached MYSQL_DATABASE: default MYSQL_HOST: db MYSQL_PASSWORD: user MYSQL_ROOT_PASSWORD: root MYSQL_USER: user PHP_IDE_CONFIG: null SECRET_ACAPI_EMAIL: null SECRET_ACAPI_KEY: null SECRET_ACQUIACLI_KEY: null SECRET_ACQUIACLI_SECRET: null SECRET_PLATFORMSH_CLI_TOKEN: null SECRET_SSH_PRIVATE_KEY: null SECRET_TERMINUS_TOKEN: null SSH_AUTH_SOCK: /.ssh-agent/proxy-socket VIRTUAL_HOST: my_project.docksal.site XDEBUG_CONFIG: client_host=172.21.67.170 remote_host=172.21.67.170 XDEBUG_ENABLED: '0' extra_hosts: my_project.docksal.site: 172.21.67.170 healthcheck: interval: 10s hostname: cli image: my_project_cli labels: io.docksal.shell: bash io.docksal.user: docker logging: options: max-file: '10' max-size: 1m volumes: - docksal_ssh_agent:/.ssh-agent:ro - cli_home:/home/docker:rw - /tmp/.docksal/my_project:/tmp/.docksal/my_project:ro - project_root:/var/www:rw,nocopy,cached db: dns: - 192.168.64.100 - 172.20.100.8 environment: MYSQL_ALLOW_EMPTY_PASSWORD: null MYSQL_DATABASE: default MYSQL_INITDB_SKIP_TZINFO: null MYSQL_ONETIME_PASSWORD: null MYSQL_PASSWORD: user MYSQL_RANDOM_ROOT_PASSWORD: null MYSQL_ROOT_PASSWORD: root MYSQL_USER: user healthcheck: interval: 10s hostname: db image: docksal/mariadb:10.3-1.1 logging: options: max-file: '10' max-size: 1m ports: - published: 33062 target: 3306 volumes: - db_data:/var/lib/mysql:rw - project_root:/var/www:ro,nocopy,cached mail: dns: - 192.168.64.100 - 172.20.100.8 healthcheck: interval: 10s hostname: mail image: mailhog/mailhog labels: io.docksal.cert-name: none io.docksal.virtual-host: mail.my_project.docksal.site,mail.my_project.docksal.site.* io.docksal.virtual-port: '8025' logging: options: max-file: '10' max-size: 1m volumes: - project_root:/var/www:ro,nocopy,cached memcached: command: - -m - '128' dns: - 192.168.64.100 - 172.20.100.8 healthcheck: interval: 10s hostname: memcached image: memcached:1.4-alpine logging: options: max-file: '10' max-size: 1m varnish: depends_on: web: condition: service_started dns: - 192.168.64.100 - 172.20.100.8 environment: VARNISH_BACKEND_HOST: web VARNISH_CACHE_TAGS_HEADER: Purge-Cache-Tags healthcheck: interval: 10s hostname: varnish image: docksal/varnish:6.1-2.0 labels: io.docksal.cert-name: none io.docksal.virtual-host: varnish.my_project.docksal.site,varnish.my_project.docksal.site.* logging: options: max-file: '10' max-size: 1m volumes: - project_root:/var/www:ro,nocopy,cached web: depends_on: cli: condition: service_started dns: - 192.168.64.100 - 172.20.100.8 environment: NGINX_BASIC_AUTH_PASS: null NGINX_BASIC_AUTH_USER: null NGINX_FCGI_HOST_PORT: cli:9000 NGINX_SERVER_ROOT: /var/www/web NGINX_VHOST_PRESET: drupal extra_hosts: my_project.docksal.site: 172.21.67.170 healthcheck: interval: 10s hostname: web image: docksal/nginx:1.14-1.0 labels: io.docksal.cert-name: none io.docksal.permanent: "false" io.docksal.project-root: /home/USER/projects/my_project io.docksal.virtual-host: my_project.docksal.site,*.my_project.docksal.site,my_project.docksal.site.* options: max-file: '10' max-size: 1m volumes: - project_root:/var/www:ro,nocopy,cached version: '3.9' volumes: cli_home: {} db_data: {} docksal_ssh_agent: external: true name: docksal_ssh_agent project_root: driver: local driver_opts: device: /home/USER/projects/my_project o: bind type: none --------------------- ```


Output of fin sysinfo:

fin sysinfo output ``` ███ FIN fin version: 1.107.1 ███ OS Linux Debian GNU/Linux 11 Linux USER-PORT 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 GNU/Linux ███ ENVIRONMENT MODE : Linux Kernel DOCKER_HOST : ███ DOCKER EXPECTED CLIENT VERSION: 20.10.7 EXPECTED SERVER VERSION: 20.10.7 Client: Docker Engine - Community Version: 20.10.12 API version: 1.41 Go version: go1.16.12 Git commit: e91ed57 Built: Mon Dec 13 11:45:37 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.12 API version: 1.41 (minimum version 1.12) Go version: go1.16.12 Git commit: 459d0df Built: Mon Dec 13 11:43:46 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.12 GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d runc: Version: 1.0.2 GitCommit: v1.0.2-0-g52b36a2 docker-init: Version: 0.19.0 GitCommit: de40ad0 ███ DOCKER COMPOSE EXPECTED VERSION: 1.29.2 docker-compose version 1.29.2, build 5becea4c docker-py version: 5.0.0 CPython version: 3.7.10 OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019 ███ DOCKSAL: PROJECTS project STATUS virtual host project root my_project Up 2 days (healthy) my_project.docksal.site,*.my_project.docksal.site,my_project.docksal.site.* /home/USER/projects/my_project ███ DOCKSAL: VIRTUAL HOSTS *.my_project.docksal.site my_project.docksal.site.* my_project.docksal.site mail.my_project.docksal.site.* mail.my_project.docksal.site varnish.my_project.docksal.site.* varnish.my_project.docksal.site ███ DOCKSAL: NETWORKING DOCKSAL_IP: 192.168.64.100 DOCKSAL_HOST_IP: 192.168.64.1 DOCKSAL_VHOST_PROXY_IP: 0.0.0.0 DOCKSAL_DNS_IP: DOCKSAL_DNS_DISABLED: 0 DOCKSAL_NO_DNS_RESOLVER: 1 DOCKSAL_DNS_UPSTREAM: 172.20.100.8 DOCKSAL_DNS_DOMAIN: docksal.site ███ DOCKSAL: CONNECTIVITY Host to 192.168.64.100: PASS Container to 192.168.64.100: PASS Container to 192.168.64.1: PASS Checking connectivity to http://dns-test.docksal.site... Host: PASS Containers: PASS ███ DOCKER: RUNNING CONTAINERS CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 07dc29f72135 docksal/varnish:6.1-2.0 "docker-entrypoint.s…" 2 days ago Up 2 days (healthy) 80/tcp, 6082/tcp my_project_varnish_1 f2a7429d5b53 docksal/nginx:1.14-1.0 "docker-entrypoint.s…" 2 days ago Up 2 days (healthy) 80/tcp, 443/tcp my_project_web_1 42f71a26ef56 docksal/mariadb:10.3-1.1 "docker-entrypoint.s…" 2 days ago Up 2 days (healthy) 0.0.0.0:33062->3306/tcp, :::33062->3306/tcp my_project_db_1 d4c4a8c9f3f1 my_project_cli "/opt/startup.sh sup…" 2 days ago Up 2 days (healthy) 22/tcp, 3000/tcp, 9000/tcp my_project_cli_1 fe874c9a219e mailhog/mailhog "MailHog" 2 days ago Up 2 days 1025/tcp, 8025/tcp my_project_mail_1 03ab100de33a memcached:1.4-alpine "docker-entrypoint.s…" 2 days ago Up 2 days 11211/tcp my_project_memcached_1 d0508359ed1b docksal/ssh-agent:1.3 "docker-entrypoint.s…" 2 days ago Up 2 days (healthy) docksal-ssh-agent 916fb13de255 docksal/dns:1.1 "docker-entrypoint.s…" 2 days ago Up 2 days (healthy) 192.168.64.100:53->53/udp docksal-dns 22db01593ebc docksal/vhost-proxy:1.7 "docker-entrypoint.s…" 2 days ago Up 2 days (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp docksal-vhost-proxy 70773e4b1c1f portainer/portainer-ce:latest "/portainer" 5 weeks ago Up 2 days 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp, 9000/tcp portainer ███ DOCKER: NETWORKS NETWORK ID NAME DRIVER SCOPE 45b4e8b90c9e _default bridge local 61f5c8a6ad2c bridge bridge local 17551ae9dec5 host host local d0c8c506b223 none null local 05a609f24a5e my_project_default bridge local ███ DOCKER DESKTOP EXPECTED VERSION: 3.4.0 DETECTED VERSION: ███ HDD Usage Filesystem Size Used Avail Use% Mounted on /dev/sdb 251G 54G 185G 23% / tmpfs 2.0G 0 2.0G 0% /wsl tools 477G 368G 110G 78% /init none 2.0G 0 2.0G 0% /dev none 2.0G 660K 2.0G 1% /run none 2.0G 0 2.0G 0% /run/lock none 2.0G 0 2.0G 0% /run/shm none 2.0G 0 2.0G 0% /run/user tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup drivers 477G 368G 110G 78% /usr/lib/wsl/drivers lib 477G 368G 110G 78% /usr/lib/wsl/lib C:\ 477G 368G 110G 78% /c ```
obriat commented 2 years ago

I hope I find a way to do it manually, could someone else test it ?

WSL and docker containers are exposed on the Windows vEthernet (WSL) interface which is a random IP 😢. So I added 192.168.64.100 as a secondary IP on the WSL eth0 interface, then, on the windows side, I added a route for it with the vEthernet (WSL) IP as gateway.

# Add an additional IP to eth0 that match docksal.site default IP
sudo ip addr add 192.168.64.100/24 broadcast 192.168.64.255 dev eth0 label eth0:1;

# Display the vEthernet (WSL) IP 
ip route list default | grep -E -o '([0-9]{1,3}[\.]){3}[0-9]{1,3}'

# Add the route
## From Powershell
route ADD 192.168.64.100 MASK 255.255.255.255 <vEthernet (WSL) IP>

## Or oneliner from WSL
powershell.exe Start-Process -Wait -Verb RunAs cmd.exe -Args "'/C', 'route ADD 192.168.64.100 MASK 255.255.255.255  $(ip route list default | grep -E -o '([0-9]{1,3}[\.]){3}[0-9]{1,3}')'"

I will do some extended tests with my coworkers on different setup : LAN, wifi, VPN, ... If it's all good and nobody else have problems with that this method could added to "fin start" (but #1643 should be fixed first)

bugsinx commented 2 years ago

Thank you so much for this i was stuck on it

sakethram171 commented 9 months ago

Thank you so much. Was stuck on it for days.