Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change permission of mounted volumes in docker-compose.yml from the docker-compose.yml?

version: '2' services:     web:         build:             context: ./             dockerfile: deploy/web.docker         volumes:             - ./:/var/www         ports:             - "8080:80"         links:             - app 

How can I change permission (chmod) /var/www automatically when docker-compose up -d --build?

like image 724
notalentgeek Avatar asked May 14 '18 07:05

notalentgeek


People also ask

How do I mount a volume in running docker container?

Cloning From An Existing Container But, if you do need to add a volume to a running container, you can use docker commit to make a new image based on that container, and then clone it with the new volume. Then, you can run the new image, replacing the old image with the cloned one.

Which is the docker syntax to locate a volume which is mounted to a container?

Using Docker's “volume create” command The docker volume create command will create a named volume. The name allows you to easily locate and assign Docker volumes to containers.

Can you mount a volume while building your docker image?

When building an image, you can't mount a volume. However, you can copy data from another image! By combining this, with a multi-stage build, you can pre-compute an expensive operation once, and re-use the resulting state as a starting point for future iterations.


2 Answers

When bind-mounting a directory from the host in a container, files and directories maintain the permissions they have on the host. This is by design: when using a bind-mount, you're giving the container access to existing files from the host, and Docker won't make modifications to those files; doing so would be very dangerous (for example, bind-mounting your home-directory would change file permissions of your host's home directory, possibly leading to your machine no longer being usable).

To change permissions of those files, change their permissions on the host.

You can find more information on this in another answer I posted on StackOverflow: https://stackoverflow.com/a/29251160/1811501

like image 56
thaJeztah Avatar answered Oct 09 '22 09:10

thaJeztah


you can add the permissions after an extra column like:

volumes:         - ./:/var/www:ro //read only 
like image 43
Edwin Avatar answered Oct 09 '22 07:10

Edwin