ptrumpis / snap-camera-server

An alternative, self-hosted solution that allows you to continue using Snap Camera with all Snapchat filters after its shutdown on January 25, 2023.
https://github.com/snapcamera
MIT License
321 stars 35 forks source link

Cannot start on windows using port 80 & 443 (WSL2 - Winnat) #147

Closed hallux4 closed 2 months ago

hallux4 commented 2 months ago

Hello,

I tried all morning to find a solution to run the nginx proxy on port 80 and 443 without success. I previously populated the config files with AutoConfig.exe from Windows Then I started the stack from Ubuntu (WSL2), it uses docker desktop (from the windows host)

docker compose up
WARN[0000] /mnt/e/Download/snap-camera-server-3.2.1.tar/snap-camera-server-3.2.1/snap-camera-server-3.2.1/docker-compose.yml: `version` is obsolete
[+] Running 5/5
 ✔ Network snap-camera-server-321_default       Created                                                                                                                               0.1s
 ✔ Container snap-camera-server-321-mysql-1     Created                                                                                                                               0.1s
 ✔ Container snap-camera-server-321-adminer-1   Created                                                                                                                               0.1s
 ✔ Container snap-camera-server-321-webapp-1    Created                                                                                                                               2.0s
 ✔ Container snap-camera-server-321-webproxy-1  Created                                                                                                                               0.1s
Attaching to adminer-1, mysql-1, webapp-1, webproxy-1
mysql-1     | 2024-06-25 11:49:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
mysql-1     | 2024-06-25 11:49:51+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-1     | 2024-06-25 11:49:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
adminer-1   | [Tue Jun 25 11:49:51 2024] PHP 7.4.33 Development Server (http://[::]:8080) started
Gracefully stopping... (press Ctrl+C again to force)
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:443 -> 0.0.0.0:0: listen tcp 0.0.0.0:443: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

It seems related to winnat.

 netsh interface ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
        22          22
        33          33
        80          80
       443         443
       ...

I tried to stop it.

net stop winnat
netsh int ipv4 add excludedportrange protocol=tcp startport=80 numberofports=1
netsh int ipv4 add excludedportrange protocol=tcp startport=443 numberofports=1

It's then possible to start the containers. But by doing so, my WSL container lost internet access. To recover I executed these commands.

wsl --shutdown # didn't help, can skip.
then I did:
ipconfig /release
ipconfige /renew

netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Then I restarted my desktop (https://github.com/microsoft/WSL/issues/3438#issuecomment-410518578)

I didn't find if it's related to docker or windows (or both) I can spin an apache2 server on ports 80/443 from my WSL2 Ubuntu without issue. But from docker, no.

It's possible to start the nginx proxy container by modifying these files.

# .env
NGINX_LOCAL_PORT=81
NGINX_DOCKER_PORT=80

# docker-compose.yml
    ports:
      - ${NGINX_LOCAL_PORT}:${NGINX_DOCKER_PORT}
      - 444:443

But then, is it possible to connect snap camera to it ?

Regards

ptrumpis commented 2 months ago

https://www.herlitz.io/2020/12/01/docker-error-ports-are-not-available-on-windows-10/

hallux4 commented 2 months ago

Thank you for the quick reply. This solution doesn't work for 80/443 I guess I tried yesterday, did it again to present the following output.

FYI antivirus disabled firewall disabled

C:\WINDOWS\system32>net stop winnat
The Windows NAT Driver service was stopped successfully.
docker compose up -d
...
docker ps
CONTAINER ID   IMAGE                           COMMAND                  CREATED         STATUS         PORTS                                      NAMES
2c7c13d8e563   nginx                           "/docker-entrypoint.…"   7 minutes ago   Up 4 minutes   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   snap-camera-server-321-webproxy-1
f69c969527be   snap-camera-server-321-webapp   "docker-entrypoint.s…"   7 minutes ago   Up 4 minutes   0.0.0.0:5645->5645/tcp                     snap-camera-server-321-webapp-1
b7a07fbf5b9d   adminer                         "entrypoint.sh php -…"   7 minutes ago   Up 4 minutes   0.0.0.0:8080->8080/tcp                     snap-camera-server-321-adminer-1
d399426bcfa4   mysql:8.0                       "docker-entrypoint.s…"   7 minutes ago   Up 4 minutes   0.0.0.0:3306->3306/tcp, 33060/tcp          snap-camera-server-321-mysql-1
C:\WINDOWS\system32>net start winnat
System error 32 has occurred.
The process cannot access the file because it is being used by another process.
docker compose down
...
C:\WINDOWS\system32>net start winnat
The Windows NAT Driver service was started successfully.
ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
8 packets transmitted, 0 received, 100% packet loss, time 7277ms

Then I have to reset everything and reboot my desktop (maybe there's another way, I dunno). It would help if someone knew ^^

I'm ok if you close the issue, the problem clearly comes from Windows or/and Docker desktop. I'll just create a Debian virtual server with a bridge connection.

Thanks for your time :-)

ptrumpis commented 2 months ago

Sorry, I don't have experience with Winnat