wger-project / docker

Production...ish docker-compose image for wger
GNU Affero General Public License v3.0
125 stars 43 forks source link

Can't start production wger docker #39

Closed zero-thermo closed 1 year ago

zero-thermo commented 1 year ago

I was able to get wger/apache up and running since it has a very straightforward docker-compose. However, it doesn't save data and everything is wiped on container restart.

How do I get the production-ish version up and running if I already have a separate Nginx Proxy Manager for my LAN-only network? Even before setting up a wger reverse proxy, I still can't access via http://PORT:IP.

docker-compose.yaml ``` version: '3.7' services: web: image: wger/server:latest container_name: wger_server depends_on: db: condition: service_healthy cache: condition: service_healthy env_file: - ./config/prod.env volumes: - static:/home/wger/static - media:/home/wger/media # For development, mount your local git checkout # - type: bind # source: /path/to/wger/sourcecode # target: /home/wger/src/ ports: - "8004:8000" healthcheck: test: wget --no-verbose --tries=1 --spider http://localhost:8000 interval: 10s timeout: 5s retries: 5 restart: unless-stopped # nginx: # image: nginx:stable # container_name: wger_nginx # depends_on: # - web # volumes: # - ./config/nginx.conf:/etc/nginx/conf.d/default.conf # - static:/wger/static:ro # - media:/wger/media:ro # ports: # - "80:80" # healthcheck: # test: service nginx status # interval: 10s # timeout: 5s # retries: 5 # restart: unless-stopped db: image: postgres:12-alpine container_name: wger_db environment: - POSTGRES_USER=wger - POSTGRES_PASSWORD=wger - POSTGRES_DB=wger volumes: - postgres-data:/var/lib/postgresql/data/ expose: - 5432 healthcheck: test: pg_isready -U wger interval: 10s timeout: 5s retries: 5 restart: unless-stopped cache: image: redis container_name: wger_cache expose: - 6379 healthcheck: test: redis-cli ping interval: 10s timeout: 5s retries: 5 restart: unless-stopped volumes: postgres-data: static: media: networks: default: name: nginx_proxy ```

Above is s the docker-compose I modified by removing the nginx section and changing the web port to 8004:8000. Starting wger this way results in "An error occurred. Something happened that caused an error." If I set DJANGO_DEBUG=True, I see the following:

connection to server at "db" (172.16.64.15), port 5432 failed: FATAL:  password authentication failed for user "wger"

prod.env and my docker-compose both retain default settings for user, password, and db, so I'm not sure why I'm getting this error. What else can I do to troubleshoot?

rolandgeider commented 1 year ago

Hi!

I would suggest changing the exposed port 80 to something that is free in your network and then using your already existing nginx to reverse proxy to it. If you want to only use one, you will need to make sure the volumes are mounted correctly and configure nginx so that it serves the static files.

As for the demo, it's supposed to be just a quick way to test the application without regards to performance or anything. Plus we're currently adding some celery workers to manage background tasks and that will probably only work correctly with this setup

zero-thermo commented 1 year ago

Hello and thanks for taking a look.

Which port 80 are you referring to? I've commented out the nginx section in docker-compose because I am already running Nginx Proxy Manager in a separate container. The only exposed ports I have are 5432 for db and 6379 cache.

I'm still running into the error even without a reverse proxy and accessing via http://IP:PORT. Do you have any other suggestions I can try to get wger up and running?

I'm new to all of this, so appreciate your patience.

rolandgeider commented 1 year ago

you can change the port exposed to the outside from 80 to something else, like 8080 in the nginx block, where it says ports so it looks like "8080:80" (line 38). That's the only thing that you'd need to change, the other two are for the db and cache and are only used internally within the containers so they are not accessible from the outside.

Then you can just take your existing nginx and add a map to the IP where the wger containers are running and port 8080 (or whatever else you chose)

I hope this helps 🀞🏻

zero-thermo commented 1 year ago

Is the nginx section of the docker-compose required for wger to work? I thought I'd be able to delete it entirely since I have a separate Nginx Proxy Manager setup, or if I wanted to run it LAN-only and access via http://PORT:IP.

When I enable the nginx section and change the external port as suggested, I get different errors when starting the container:

DoesNotExist at /en/software/features

Language matching query does not exist.
rolandgeider commented 1 year ago

yeah, it's needed. I mean, you could probably make yours work with it, but it will be some work (but it should be possible in theory), "our" nginx isn't only a reverse proxy to the application, it also serves the static files.

As for the error message, I'm guessing there was something wrong when the containers first started. Can you delete all volumes and start again?

zero-thermo commented 1 year ago

Found the issue. wger was connected to a Docker bridge network with other containers, and for some reason wger db commands were being routed to the postgres of another container/service. Why would this happen?

Doing the following got wger working:

Thanks for your patience and help. I wouldn't have figured out how to get this running otherwise.

rolandgeider commented 1 year ago

ugh alright, I wouldn't have guessed it was that πŸ˜…

rolandgeider commented 1 year ago

so does the app correctly load the css and js files when accessing it over the domain?

zero-thermo commented 1 year ago

Looks like I spoke too soon πŸ˜…

Accessing over the domain loads the main wger welcome page, but the service itself is not fully functioning. For example, once logged in as admin, I cannot bring up the drop down menu in the top right to add users or logout. The wger logo is also missing from the top left.

Checking the wger_nginx logs show errors like this one:

2022/11/06 21:06:42 [error] 30#30: *1698 open() "/wger/static/images/icons/flag-nl.svg" failed (2: No such file or directory), client: 172.16.16.1, server: , request: "GET /static/images/icons/flag-nl.svg HTTP/1.1", host: "wger.mydomain.tld", referrer: "https://wger.mydomain.tld/en/dashboard"
rolandgeider commented 1 year ago

Looks like I spoke too soon πŸ˜…

I know that feeling!

So some of the css/images arebeing loaded correctly and others are not? πŸ€” That would be a new one.

BTW, how did you configure the network?

zero-thermo commented 1 year ago

Yes it looks like some assets are loaded correctly, but others are not and showing errors in logs.

In my docker-compose: web port left at 8000
nginx changed to 84:80 (84 is not a conflict with any other Docker service ports)
db port left at 5432
cache port left at 6379

wger is completely isolated in its own Docker network wger_default

Nginx Reverse Proxy manager is set to pass wger.mydomain.tld to http://192.168.1.15:84 (local server IP and wger port). This is a LAN-only reverse proxy.

rolandgeider commented 1 year ago

That's really strange. Perhaps you can drop the volume used for the static files and start again. There's a step in the boot process where the files are copied over, there might be some error message there

zero-thermo commented 1 year ago

Hello again. I dropped the volumes and started over, but am still seeing text-only without any of the static images.

wger_server logs are below, and I don't see any step where the files are copied over:

yarn install v1.22.19
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
Done in 4.95s.
yarn run v1.22.19
$ sass wger/core/static/scss/main.scss:wger/core/static/yarn/bootstrap-compiled.css
Done in 2.22s.
Set site URL to http://localhost:8000
Using gunicorn...
[2023-01-08 19:57:19 +0000] [57] [INFO] Starting gunicorn 20.1.0
[2023-01-08 19:57:19 +0000] [57] [INFO] Listening at: http://0.0.0.0:8000 (57)
[2023-01-08 19:57:19 +0000] [57] [INFO] Using worker: sync
[2023-01-08 19:57:19 +0000] [58] [INFO] Booting worker with pid: 58

/home/wger/static in the wger_server container is also empty with no files.

zero-thermo commented 1 year ago

Figured it out: need to change DJANGO_DEBUG back to False in prod.env

Looking forward to using wger. Thanks for your continued work on this project.

rolandgeider commented 1 year ago

FYI, when setting debug to true, you are using django's dev server. While this will work fine, it is not meant to be used for production (in case you get some unusually high memory usage or stuff like that).