Bubka / 2FAuth

A Web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
https://docs.2fauth.app/
GNU Affero General Public License v3.0
2.31k stars 152 forks source link

Fail to use docker to deploy on the device in the LAN #398

Closed puerro closed 3 weeks ago

puerro commented 1 month ago

My main router ip is 192.168.1.1 I get a ubuntu server (headless no Desktop) is DHCP ip (192.168.1.2), not static ip Docker installed in this ubuntu server Port 8000 used by portainer-ce, so I have to use 8001

docker run -d -p 8001:8000/tcp \
-e APP_KEY=[hide] \
-e APP_URL=http://localhost:8001 \
-v ~/.2fauth:/2fauth \
--name 2fauth \
--restart=on-failure \
2fauth/2fauth:latest

I want use my PC (192.168.1.*) access 192.168.1.2:8001, it doesn't work

root@ubuntu:~# docker run -d -p 8001:8000/tcp \
> -e APP_KEY=[hide] \
> -e APP_URL=http://localhost:8001 \
> -v ~/.2fauth:/2fauth \
> --name 2fauth \
> --restart=on-failure \
> 2fauth/2fauth:latest
33efeb2fb9998ed5d66b9f0dcf7b08989acf98dba0240451dfe36b9c1885412d
root@ubuntu:~# docker ps
CONTAINER ID   IMAGE                           COMMAND                  CREATED         STATUS                        PORTS                                                                                            NAMES
33efeb2fb999   2fauth/2fauth:latest            "/usr/local/bin/entr…"   8 seconds ago   Restarting (1) 1 second ago                                                                                                    2fauth

What should I do?

Bubka commented 1 month ago

Hi, What do you mean by:

it doesn't work

puerro commented 1 month ago

Hi, What do you mean by:

it doesn't work

I can't install with docker.

STATUS
Restarting (1) 1 second ago

docker ps always show restarting, reboot also, and 192.168.1.2:8001 webpage show error.

Bubka commented 1 month ago

-v ~/.2fauth:/2fauth \

Is /.2fauth instead of ./2fauth voluntary?

puerro commented 1 month ago

My bad. I didn't see the docs.

Use:

mkdir .2fauth
chown 1000:1000 .2fauth
chmod 700 .2fauth

It works.

docker ps show running, reboot also.

When visit 192.168.1.2:8001, the webpage is blank, the webpage title show 2FAuth. I need add set -e ASSET_URL=http://localhost:8001 \ ?

Bubka commented 1 month ago

The most important is APP_URL, it must reflect the url in the address bar, so APP_URL=http://localhost:8001, or APP_URL=http://192.168.1.2:8001 if localhost is not bound to 192.168.1.2. Do not forget to use https if you have such a connection. You have to set ASSET_URL if and only if you serve js/css assets from another server, otherwise it will fall back to the APP_URL value.

puerro commented 1 month ago
root@ubuntu:~# cat /etc/hosts
127.0.0.1       localhost
::1             localhost

Huh... 192.168.1.2 is a DHCP ip, actually the ubuntu server is removable, I don't want to change it become static ip. And the DHCP ip will change, that means not support visit DHCP ip in the LAN?

Bubka commented 1 month ago

How do you reach your server if its ip address changes all the time without a bound domain?! I'm not an ops specialist, so maybe I'm missing something, but to me it doesn't make sense.

puerro commented 3 weeks ago

My main router 192.168.1.1, also DHCP server, that have all DHCP ip in the LAN. Of course I can visit main router get DHCP ip at home, but may not if I move the ubuntu server.

I have to set a static ip APP_URL=http://192.168.1.2:8001, it works perfectly.

Bubka commented 3 weeks ago

Ok 👍🏻 Issue closed as it works, feel free to reopen it if necessary.