Title: Docker volume usage for storing jpg
Tags: laravel;docker;png;jpeg;docker-volume
Question: So, i built a small application to test how docker works, is a small laravel app that registers users with its profile image. Everything is working properly but the profile image is not being display.
I assume this is because how docker works (ephemeral, unchange, etc), so i was reading a bit about volumes but unfortunately i was not able to make it work.
The images are stored inside a folder called uploads within public folder (laravel structure).
In my docker-compose.yml file i have the following volumes defined:
volumes:
- mysql-data:/var/lib/mysql
So i tried to add the one that i need, something like this:
volumes:
- mysql-data:/var/lib/mysql
- user-images:/app/public/uploads
volumes:
mysql-data:
user-images:
I also tried with bind mounts but i think this can only be used using docker container run (not quite sure).
Any idea on how could i fix this?
Thanks
Comment: what is the permission on `user-images` directory ? share output of `ls -l user-images`

Comment: what is the ownership ? and are you running your application with different user inside container or root user ?

Comment: `docker run -itd --name name-of-container -v host-dir:container-dir name-of-image` ? share the output of this command here replce whatever volumes you are using for like mysql-data, user-images

Comment: so are you starting your application with `root` or `angel` ?

Comment: Hi, the permissions are  "drwxrwxr-x" for both public and uploads folder.

Comment: Sorry, the ownership inside the container is root:root. For running the container i use my username "angel".

Here is the accepted answer: user-images:/app/public/uploads would be a named volume, defined in /var/lib/docker/volumes
If you want to use a bind mount, that is mounting an host folder as a volume, use a path:
volumes:
- "./user-images:/app/public/uploads"
See also "Laravel + Docker" and its part 2 for a more complete example.
Comment for this answer: not working, i just add a file in `/app/public/uploads` , but its not showing up in `./user-images`, what happen?
Comment for this answer: @aswzen not sure, could you ask a separate question with more details for me or others to have a look?

Here is another answer: I'm assuming your image is in directory tree with the dockerfile/docker-compose. If that is the case you actually don't want to use a named volume given those are stored elsewhere on your system and would require you move your image to that location. (see "Mountpoint" in image below)
What you likely want to use is the --mount flag which in your compose file would look like so...
volumes:
- type: bind
source: ./path/to/file
target: /app/public/uploads
See docker volumes docks for more info. I wrote the long version which I prefer as it's more explicit but the sort version does the same thing. You should be aware that using a bind volume will overwrite any files you might of added to the actual image if they overlap. Tip this is handy when you have a hot reloading dev server as you can change your files locally and they be ran in the containers context.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 6, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2018:00:03/31/18', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<laravel><docker><png><jpeg><docker-volume>', 'Title': 'Docker volume usage for storing jpg', 'ViewCount': 2115, 'id': 49584448, 'user_AboutMe': None, 'user_AccountId': 13109044.0, 'user_DisplayName': 'Angel Gutierrez', 'user_Reputation': 41.0, 'user_Views': 3.0, 'user_id': 9470769.0}}