docker icon indicating copy to clipboard operation
docker copied to clipboard

How I got it working

Open deboy69 opened this issue 1 year ago • 12 comments

You maybe like me and stuggled for days to get this to work. There are so many little errors in this project that don't really get fixed. 1. permissions and 2. django set to false (causes it not to load properly). I used portainer which needs stack.env instead of prod.env to run. Adjust either way you use it.

Here is what I used to get this working. I dont use celery and I dont use the included Nginx, I use NPM. Once you get it up for the first time, chmod 777 -R /static and chmod 777 -R /media. Re run the container again. ssh into the container didnt work for me so I used portainer cmd. Hope this helps

once into the container run the following. python3manage.py sync-exercies   python3 manage.py download-exercise-images   python3 manage.py download-exercise-videos/   python3 manage.py sync-ingredients

Portainer stack or you can use compose.

services: web: image: wger/server:latest env_file: - stack.env volumes: - your local path/wger/static:/home/wger/static:rw - your local path/wger/media:/home/wger/media:rw environment: - UMASK=022 - PUID=0 - PGID=0 ports: - 8011:8000 #change 8011 if you have 8000 in use already healthcheck: test: wget --no-verbose --tries=1 --spider http://localhost:8000 interval: 10s timeout: 5s start_period: 300s retries: 5

db: image: postgres:15-alpine environment: - POSTGRES_USER=wger - POSTGRES_PASSWORD=wger - POSTGRES_DB=wger volumes: - your local path/ wger/postgres-data:/var/lib/postgresql/data expose: - 5432 restart: unless-stopped healthcheck: test: pg_isready -U wger interval: 10s timeout: 5s retries: 5 start_period: 30s ########################################################
cache: image: redis expose: - 6379 volumes: -your local path/wger/redis-data:/data restart: unless-stopped healthcheck: test: redis-cli ping interval: 10s timeout: 5s retries: 5 start_period: 30s ##########################################################

networks: default: name: wger_network

#############################################################################################

For NPM this goes in the advanced settings

location / { proxy_pass http://ip address:port# proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; proxy_set_header X-Forwarded-Host $host:$server_port; proxy_redirect off; }

location /static/ { alias /wger/static/; }

location /media/ { alias /wger/media/; }

deboy69 avatar Oct 28 '24 18:10 deboy69

Adjustment for NPM

For NPM this goes in the advanced settings

location / { proxy_pass http://ip/ address:port# proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; proxy_set_header X-Forwarded-Host $host:$server_port; proxy_redirect off; }

location {location of your static folder}/static/ { alias /wger/static/; }

location {location of your media folder}/media/ { alias /wger/media/; }

deboy69 avatar Oct 28 '24 18:10 deboy69

Can I ask what your .env file looks like? I have a very similiar setup also using NPM without celery and nginx but can't get it to work.

docker-compose.yml:

 services:
  fitness-app:
    container_name: fitness-app
    image: wger/server:latest
    depends_on:
      fitness-db:
        condition: service_healthy
      fitness-cache:
        condition: service_healthy
    env_file:
      - ./folder/.wger_env
    volumes:
      - ./folder/www:/home/wger/static
      - ./folder/media:/home/wger/media
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:8000
      interval: 10s
      timeout: 5s
      start_period: 300s
      retries: 5
    restart: unless-stopped
    networks: 
      - fitness-net
      - nginx-proxy-manager

  fitness-db:
    container_name: fitness-db
    image: postgres:15-alpine
    environment:
      - POSTGRES_USER=wger
      - POSTGRES_PASSWORD=PASSWORD
      - POSTGRES_DB=NAME
    volumes:
      - ./folder/db:/var/lib/postgresql/data/
    healthcheck:
      test: pg_isready -U wger
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    restart: unless-stopped
    networks: 
      - fitness-net

  fitness-cache:
    container_name: fitness-cache
    image: redis
    volumes:
      - ./folder/cache:/data
    healthcheck:
      test: redis-cli ping
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    restart: unless-stopped
    networks: 
      - fitness-net

networks:
  nginx-proxy-manager:
    external: true
  fitness-net:
    name: fitness-net
    driver: bridge

Custom Nginx Configuration:

location / {
proxy_pass http://fitness-app:8000
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_redirect off;
}

location ./folder/static/ {
alias /wger/static/;
}

location ./folder/media/ {
alias /wger/media/;
}

chrisbehectik avatar Jan 10 '25 01:01 chrisbehectik

Note that using folders directly does cause problems (I have added a warning to the docs right now), if you get a set of steps to do so that everything works, I'll gladly add it to the readme

rolandgeider avatar Jan 10 '25 18:01 rolandgeider

Note that using folders directly does cause problems (I have added a warning to the docs right now), if you get a set of steps to do so that everything works, I'll gladly add it to the readme

What do you mean directly? Can you elaborate on that for clarification? Thanks

deboy69 avatar Jan 14 '25 13:01 deboy69

What do you mean directly? Can you elaborate on that for clarification? Thanks

@deboy69 sure, I mean mounting folders instead of using the volumes, so - ./folder/www:/home/wger/static vs - static:/wger/static:ro. Django collects static files from the application folder and copies them to static, which are then read and served by the web server and there are probably some user IDs mismatch (this could be fixed by running some chmod commands, but then you would need to do that every time something changes). Also this is only important for the static and media folders, cache, db etc should work fine without volumes

rolandgeider avatar Jan 17 '25 16:01 rolandgeider

@rolandgeider I have also tried the various permutation and combination of config as suggested by others here since full week as I want to really use it for fitness routine recording but I have failed to make it work.

With local folder approach on all except nginx, it started with warning and some error but could open the webpage with all images on index page, registered on it and login but could sync exercises but could not download the images because of python code errors.

Without local folder and only volume overall, it does start without error but later celerarybeat throw an error about permission denied. And it has no registration option, the first page open as guest and when I login using default admin and password adminadmin, it shows cross site security error.

docker compose file:

services: web: image: wger/server:latest depends_on: db: condition: service_healthy cache: condition: service_healthy env_file: - ./config/prod.env volumes: - static:/home/wger/static:rw - media:/home/wger/media:rw expose: - 8000 healthcheck: test: wget --no-verbose --tries=1 --spider http://localhost:8000 interval: 10s timeout: 5s start_period: 300s retries: 5 restart: unless-stopped

nginx: image: nginx:stable depends_on: - web volumes: - ./config/nginx.conf:/etc/nginx/conf.d/default.conf - static:/wger/static:ro - media:/wger/media:ro ports: - "8000:80" healthcheck: test: service nginx status interval: 10s timeout: 5s retries: 5 start_period: 30s restart: unless-stopped

db: image: postgres:15-alpine environment: - POSTGRES_USER=wger - POSTGRES_PASSWORD=wger - POSTGRES_DB=wger volumes: - /volume1/docker/wger/db:/var/lib/postgresql/data/:rw expose: - 5432 healthcheck: test: pg_isready -U wger interval: 10s timeout: 5s retries: 5 start_period: 30s restart: unless-stopped

cache: image: redis expose: - 6379 volumes: - /volume1/docker/wger/redis:/data:rw healthcheck: test: redis-cli ping interval: 10s timeout: 5s retries: 5 start_period: 30s restart: unless-stopped

celery_worker: image: wger/server:latest command: /start-worker env_file: - ./config/prod.env volumes: - media:/home/wger/media:rw depends_on: web: condition: service_healthy healthcheck: test: celery -A wger inspect ping interval: 10s timeout: 5s retries: 5 start_period: 30s

celery_beat: image: wger/server:latest command: /start-beat volumes: - /volume1/docker/wger/beat:/home/wger/beat/:rw env_file: - ./config/prod.env depends_on: celery_worker: condition: service_healthy

volumes: postgres-data: celery-beat: static: media: redis-data:

networks: default: name: wger_network`

##########################################################

Ngnix file:

upstream wger { server web:8000; }

server {

  listen 80;

  location / {
      proxy_pass http://wger;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
      proxy_set_header X-Forwarded-Host $host:$server_port;
      proxy_redirect off;
  }

  location /static/ {
      alias /wger/static/;
  }

  location /media/ {
      alias /wger/media/;
  }
  client_max_body_size 100M;

}

###############################################################

First page:

Image

Error:

Image

cogentcoder avatar Feb 13 '25 22:02 cogentcoder

@rolandgeider I changed the redis, beat and worker to volume. Database has local folder with rw permission as before, changed localhost to site url in prod.env in docker-compose.yaml but still I have CRSF token error.

In internet, people are saying those token code need some modification in settings.py but the file in the container not writeable to try any solution.

Any suggestion to solve this issue?

cogentcoder avatar Feb 14 '25 15:02 cogentcoder

@cogentcoder you need to add that ip and port to CSRF_TRUSTED_ORIGINS to the env file, sadly there's no way to allow everything, you need to add each ip and domain you might be accessing this from. Also remember to set debug to false once you can log so that django doesn't serve the static files itself.

rolandgeider avatar Feb 16 '25 14:02 rolandgeider

@rolandgeider Thank you! Yes, CSRF_TRUSTED_ORIGINS was the issue. I've adjusted as per your advice and now, it is successfully installed and could also sync and downloaded exercises, images and videos too without any error in the log.

But some issues are noticed:

  1. It does not display any images in exercise browser page. For the exercise, it shows the muscle group only, the exercise image is not shown and video panel exist but doesn't play anything.

Image

Image

  1. There are some errors during docker compose exec web python3 manage.py sync-ingredients-async . Attached the log file.

wger-celery_worker-1.csv

cogentcoder avatar Feb 16 '25 19:02 cogentcoder

@cogentcoder there might have been some problems during sync? or it might be again be permission errors. Can you check if they are present in the volume? If not, you can delete the images and videos, run the sync commands again and see if it works. To delete them:

docker compose exec db psql -U wger -c "DELETE FROM exercises_exerciseimage;"
docker compose exec db psql -U wger -c "DELETE FROM exercises_exercisevideo;"

As for the ingrediend sync, it seems that there was an empty response once but at least the rest of the ingredients did indeed go through, we should catch that error though

rolandgeider avatar Feb 16 '25 19:02 rolandgeider

@rolandgeider As the deleting and re downloading of the images and video in previous suggestion didn't change anything, I tried db as a volume instead of folder. Now, it shows the images and videos. The video playback seems fine though not all images are shows as in the screenshot.

Image

Beside changing db to volume (all other were volume already), I have made other changes which might be reason.

In prod.env file, there are lines for static files. I've un-commenting those line to the below

MEDIA_URL=http://192.168.30.160:8000/media/
STATIC_URL=http://192.168.30.160:8000/static/

I'm using Synology 220+ Nas which has dual core intel with 18 GB memory. UID and GID found to be 1026 and 100 respectively so tried putting that in prod.env like below

PUID=1026
PGID=100

I have noticed errors in wger-web. Log file is attached.

wger-web-1.csv

cogentcoder avatar Feb 17 '25 16:02 cogentcoder

mhh, an out of memory error? can you run docker stats --no-stream to see what the containers are doing?

(BTW not all exercises have images, but we decided to still put them front and center like that so that people would contribute them)

rolandgeider avatar Feb 19 '25 14:02 rolandgeider