snipe-it
snipe-it copied to clipboard
Docker volume for uploads is an ID
Hello,
I created a docker compose that works fine. However when I upload a document in Snipe-IT I can see in the link an ID. This ID is the ID of the volume docker created. Inside /var/lib/docker/volumes I can see the both volumes I created in the docker-compose but there is a 3rd volume. Inside this 3rd volume there are the 2 directories for uploads.
I dropped the container and I recreated from my docker-compose then the ID change. I restore the content of the MySQL database and all data are there. But If I clic on a document the link is not working anymore because of a wrong ID.
Is there a possibility to store the uploads in a "known" directory?
I don't know much about docker-compose, but I do know that our Dockerfile expects to find a volume mounted on /var/lib/snipeit
. If you didn't explicitly mention a volume mount there, I suspect that Docker is just generating a random ID for the volume and mounting it there. You can probably explicitly reference that ID and that you want it to mount there, and then your images should come back.
We try (perhaps not always succeed) to follow the Docker ethos of making our containers be 'disposable' - hence the volume reference in the Dockerfile. Your uploads should persist even if you throw away the container and regenerate it.
If you're seeing something in your broken-image URL's that actually mentions the weird random ID of your volume, that seems weird. Snipe-IT definitely doesn't do that. I just hope that Docker isn't doing something weird here.
If you can share any docker-compose files or environment files (with sensitive data redacted, of course) maybe I can help you figure out what's going wrong.
Here is the docker-compose.yml
version: "3.5"
volumes:
snipe_db_data:
snipe_it_data:
services:
mysql:
image: mysql:5.7
container_name: snipe_mysql
restart: always
volumes:
- snipe_db_data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=mypass
- MYSQL_USER=snipe
- MYSQL_PASSWORD=mypassagain
- MYSQL_DATABASE=snipe
ports:
- "3306:3306"
snipeit:
image: snipe/snipe-it:latest
container_name: snipeit
restart: always
volumes:
- snipe_it_data:/var/www/html
depends_on:
- mysql
environment:
- APP_URL=asset.localdomain.com
- APP_ENV=production
- APP_DEBUG=false
- APP_KEY=base64:hDA2W2DmVefefefevdvmfimfiEdr3rt3j
- MYSQL_PORT_3306_TCP_ADDR=mysql
- MYSQL_PORT_3306_TCP_PORT=3306
- MYSQL_DATABASE=snipe
- MYSQL_USER=snipe
- MYSQL_PASSWORD=mypass
- PGID=1000
- PUID=1000
- SNIPEIT_APP_NAME="Assets Management"
- SNIPEIT_APP_DIR=/var/www/html
- SNIPEIT_TARBALL=/tmp/snipeit_tar/
ports:
- "80:80"
I think the piece that you wanted was this:
services:
snipeit:
volumes:
- snipe_it_data:/var/lib/snipeit
I suspect your snipe_it_data
volume is empty? Or does it have a full Snipe-IT installation on it?
docker-compose up -d
Creating network "snipeit_default" with the default driver
Creating volume "snipeit_snipe_db_data" with default driver
Creating volume "snipeit_snipe_it_data" with default driver
Creating snipe_mysql ... done
Creating snipeit ... done
And then if I check the snipe_it_data
volume
ls /var/lib/docker/volumes/snipeit_snipe_it_data/_data
CODE_OF_CONDUCT.md Vagrantfile c3.php database phpmd.xml server.php upgrade.php
CONTRIBUTING.md _config.yml codeception.yml docker phpunit.xml snipeit.sh vendor
Dockerfile ansible composer.json index.html public storage webpack.mix.js
Dockerfile.alpine app composer.lock install.sh resources supervisord.log
LICENSE artisan config package-lock.json routes supervisord.pid
README.md bootstrap crowdin.yml package.json sample_csvs tests
The real directory is prefixed by snipeit_ but it is not empty.
The content of the /var/lib/docker/volumes
ls /var/lib/docker/volumes/
ba1f5e573c61a9cd0f73f3a8495815762977a20d1a79158cf6692e57a2ba9786 metadata.db snipeit_snipe_db_data snipeit_snipe_it_data
ls /var/lib/docker/volumes/ba1f5e573c61a9cd0f73f3a8495815762977a20d1a79158cf6692e57a2ba9786/_data/data/ private_uploads uploads
I tried to start the docker compose with a recreate option
docker-compose up -d --force-recreate snipeit Recreating snipe_mysql ... done Creating snipeit ... done
then it generates a new ID for the volume meaning mysql is not in cause only the service snipeit generate this behaviour.
I just spent some time figuring out how snipe's volumes work. I believe that the point of confusion is that snipe's dockerfile has this line in it: VOLUME ["/var/lib/snipeit"]
This means that docker will create an anonymous volume (long random name in the host system), UNLESS a volume with the same path is declared either in docker run
command or docker-compose.yml
. I.e. @uberbrady's proposal works for me.