dperson / samba

Samba docker container
GNU Affero General Public License v3.0
1.52k stars 514 forks source link

What's the purpose of the VOLUMEs in the Dockerfile? #446

Open western-hoolock opened 1 year ago

western-hoolock commented 1 year ago

I'm using this image with a docker-compose file to set environment variables, works nicely. However the VOLUME in the Dockerfile of this image is causing 5 new volume to be created every single time I do a docker-compose up/down. What's the purpose of declaring those VOLUMEs in the Dockerfile? I know I can declare named volumes in my docker-compose file but I'm not sure why the VOLUME is needed in the Dockerfile in the first place.

codefox42 commented 1 year ago

I must admit, that the documentation does not provide much guidance regarding when to declare VOLUMEs and when not. Some even advice against using this feature.

I think wisely used, VOLUMEs are a good thing, as they clearly define where a specific application is writing data to that one might want to persist. On the other hand it is up to the user to hook up named volumes he/she is interested in. Nevertheless it is important to know how to get rid of the anonymous volumes that are automatically created if you don't explicitly specify a volume. It depends on how you are running the container:

docker compose down --volumes

docker container rm --volumes

(For single short-lived experimental containers I prefer using docker run --rm ... in the first place which also takes care of removing anonymous volumes.)

leoleozhu commented 12 months ago

Now I understand why the previously configured shares are still accessible. The smb.conf file is located in the /etc volume created by the Dockerfile. So whenever I modify the SHARE environment variable in the docker-compose.yml file, it is appended to the configuration file, and the previous one is not erased even if the container is recreated.

This is not a common practice in Docker. If the configuration is intended to be persistent, the documentation should recommend that users supply a volume for that directory.