aspendigital / docker-octobercms

Dockerized October CMS: PHP, Composer, October core and dependencies
MIT License
150 stars 55 forks source link

Mounting new .env caused created the file on host by root instead of www-data #14

Closed andriansandi closed 6 years ago

andriansandi commented 6 years ago

I have a problem that I wanted to mounted new file called .env, but in the host it created by root instead of www-data

Step to reproduce

  1. existing docker images run by docker-compose up -d before
  2. Add new file in the local called .env
  3. update docker-compose.yml to mount new file - ./.env:/var/www/html.env
  4. The new .env shows created and owned by root instead of ww-data

It's caused the application error.

How I can solved it ?

petehalverson commented 6 years ago

I'm guessing it's a typo, but using - ./.env:/var/www/html.env would mount that file as /var/www/html.env in the container.

Regardless, check the permissions of the .env file on your local machine which you're mounting in the container. Permissions on mounted volumes will be the same both inside and outside of the container. If it's set as root it will be root in the container. If you change it to www-data, it will be www-data in the container.

I should note, if the local file you referenced in docker-compose.yml doesn't exist when you run docker-compose up, the container will create a folder on your local machine with the root user.

petehalverson commented 6 years ago

If you don't have a www-data:www-data user:group setup in OS X, what I described above doesn't really fly.

However, Docker For Mac does something interesting. If you update the file's permissions from within the container, it's permissions persist on the host as an extended attribute ls -@la .env

https://docs.docker.com/docker-for-mac/osxfs/#ownership