wger-project / docker

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

No persistant data #20

Open deboy69 opened 2 years ago

deboy69 commented 2 years ago

Hi, running into an issue with persistant data. I copied the persistant location via the docker-compose file. I get the docker running, but if I update the image all my data is gone. My static locations and media locations are all empty. Any thoughts or ideas?

Thanks

ShadowOTE commented 2 years ago

Just went thru and did a docker production install last night, and I'm also seeing this issue - my local folders are empty when I map them to /media and /static, and when I drop in to the running container, /media and /static are both empty folders in wger/server:latest. I think what may have happened is in the latest build /media and /static are in the wrong spot - instead, they are in ~/media and ~/static. This would explain why when I open the webpage all the CSS and media files come back as 404 Not Found responses - they're still looking in /static/ (eg, /static/css/agency.css, which doesnt exist).

ShadowOTE commented 2 years ago

Ok - disregard the above. Turns out it was an artifact of how I was mounting the volumes. If you're using the standard docker-compose file, you should note the final 3 lines define the creation of the volumes shared across the various services. You'll want to update the docker-compose file to look something like the following:

volumes:
  postgres-data:/path/to/my/persisted/db/folder
  static:/path/to/my/persisted/static/folder
  media:/path/to/my/persisted/media/folder

I think once you do that and restart the container things should look better.

deboy69 commented 2 years ago

Tried it. Wouldnt map. Do you have a better example? is the /path/to/my.... inside the container location or on the host location?

rolandgeider commented 2 years ago

you can't map the paths there, those are docker volumes and are managed by the docker system. You can however take a look at the location where the data is with docker volume inspect docker_postgres-data.

I also wrote in the other issue that I still haven't been able to reproduce this. Are you guys also losing the data with the regular docker compose file?

ShadowOTE commented 2 years ago

Gotcha - that makes sense. I was using the synology GUI tools to build the containers, and haven’t used docker-compose much before - thanks for clarifying. The other issue I ran into was a permissions issue where the wger user didn’t have write access to mapped folders (eg, most folders in ~ had a group and owner of “wger”, while the mapped ~/media and ~/static folders had a group of 123 and owner of 1001). Eventually solved it by sshing in and chmod 777ing the directory I was mounting, after which wger could write successfully; it’s also possible I needed to supply :Z as part of the mounting instructions (though the synology Ui may have made that impossible; not 100% sure as I didn’t try). That said, prior to chmoding the directory I had tried setting the PUID and GUID env variables, which would have granted the in-container wger account access had the app run under the supplied account IDs. Might be something to look into.

deboy69 commented 2 years ago

Ya nothing is going into the media/static folders. I would like to see all the config data go into one folder also since i use duplicati as a backup program. Appears mapping the persistant drives isnt really working withing the container.

Yes, to using the docker-compose file in the repo here.

Yes, everything gets overwritten every time I redeploy the container

deboy69 commented 2 years ago

the persistant volumes dont map. seems to either be a mapping issue or a persistant volume overwrite issue.

postmaster.pid and postmaster.opts seem to be the only file that gets rewritten with a docker update or redeploy in the postgres_data volume/mapped folder

deboy69 commented 2 years ago

so ran sudo docker-compose exec web python3 manage.py download-exercise-images says permission denied than I cd into the container, ran chmod 777 to the media folder and now it installs. So narrowed it down to a permissions issue.

deboy69 commented 2 years ago

But still have the issue of all my persistant data being rewritten with every deployment of docker-compose.

deboy69 commented 2 years ago

@rolandgeider

I wanted to add that I am using Docker (rpi) with Portainer and deploying this over a stack. Using watchtower to update the containers.

Also tried using the docker-compose.yml and following step by step guide, down pull up sequence with no change.

here is my docker compose file. Seems that something in the postgress is not following the mapped volumes. I just cant track it down to why.

Also what is suppose to go into the static file? The file just ends up being empty.

version: '3.7'

services: web: image: wger/server:latest volumes:

nginx:

build: ./nginx

volumes:

- static:/wger/static:ro

- media:/wger/media:ro

ports:

- 80:80

depends_on:

- web

db: image: postgres:12-alpine volumes:

deboy69 commented 2 years ago

Update. I believe the .prod.env is mandotory. Without it,the persistant would just not work. Ill keep an eye on it and see if it continues to work with new docker pulls

rolandgeider commented 2 years ago

just merged a small PR to master, there should be new images published soon

rolandgeider commented 2 years ago

Update. I believe the .prod.env is mandotory. Without it,the persistant would just not work. Ill keep an eye on it and see if it continues to work with new docker pulls

you are right. Particularly DJANGO_DB_ENGINE needs to be set, otherwise django creates an sqlite file which gets overwritten with new images