Open Luxtech opened 3 years ago
I believe that what is happening is that the image has files in those directories, thus directories like /var/www/html/data are overridden by empty ones when the volumes are mounted. Docker initializes named volumes with the contents of the image so this problem doesn't happen.
I am trying to do the same thing for the same reason and seeing the same issue. I have tried running the original docker-compose file to create a good set of volume related files in /var/lib/docker/volumes, shutting it down, then copying them to where I really want them and updating the docker-compose file to point there and then bringing it back up. It throws a forbidden error so clearly I don't understand enough about how docker works to solve this problem at this time.
You can use a third one time "init" container to copy the correct files to the non default location bind mounted volumes. I am attaching an excerpt of a working docker-compose.yaml file that bind mounts /data/docker/partkeepr/{conf,data,web} as volumes and attaches them to the partkeepr , partkeepr-cronjob and partkeepr-init containers.
docker-compose up partkeepr-init
to initialize your bind mounted folders and wait until it rsyncs the data. partkeepr:
image: mhubig/partkeepr:latest
container_name: partkeepr
environment:
...
volumes:
- partkeepr-conf:/var/www/html/app/config
- partkeepr-data:/var/www/html/data
- partkeepr-web:/var/www/html/web
partkeepr-cronjob:
...
volumes:
- partkeepr-conf:/var/www/html/app/config
- partkeepr-data:/var/www/html/data
- partkeepr-web:/var/www/html/web
partkeepr-init:
image: mhubig/partkeepr:latest
restart: "no"
entrypoint: []
command: bash -c "apt update && apt install -y rsync && rsync -avHhSp /var/www/ /var/www-dest/"
volumes:
- partkeepr-conf:/var/www-dest/html/app/config
- partkeepr-data:/var/www-dest/html/data
- partkeepr-web:/var/www-dest/html/web
volumes:
partkeepr-conf:
driver: local
driver_opts:
o: bind
type: none
device: /data/docker/partkeepr/conf
partkeepr-data:
driver: local
driver_opts:
o: bind
type: none
device: /data/docker/partkeepr/data
partkeepr-web:
driver: local
driver_opts:
o: bind
type: none
device: /data/docker/partkeepr/web
ngtech's solution worked for me. I also copied over the database seperately from the standard location to the custom location and it works as intended.
I had a similar issue with a container running in a Kubernetes Pod and using an init-container like @ngtech mentioned worked like a charm. Thanks!
I cloned the git repo and edited the docker-compose file so that volumes are located in a known location. This is something that I always do for docker projects so that I can backup the volumes easily. When i changed the location of the volumes for this partkeepr container the http://localhost:8080/setup/ gives this error:
Not Found The requested URL was not found on this server
If I keep the original docker-compose file the setup works.Can someone help me to solve this problem? Or is it not possible to change the volume locations?
My docker-compose file: