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
?
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.
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.
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.
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
you can add the permissions after an extra column like:
volumes: - ./:/var/www:ro //read only
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With