Skip to content

PHP container's userid and groupid VS host machine's userid and groupid #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
perarg opened this issue Jan 29, 2018 · 2 comments
Closed

Comments

@perarg
Copy link

perarg commented Jan 29, 2018

I have setup a docker container with ex. php:5.6.33-fpm-alpine. My docker-compose.yml file is the following

version: "3.3"
services:
  example:
    image: php:5.6.33-fpm-alpine
    container_name: example
    environment:
      - VIRTUAL_HOST=example.com
      - VIRTUAL_ROOT=/var/www/example.com/html
      - VIRTUAL_PORT=9000
      - VIRTUAL_PROTO=fastcgi
    restart: always
    ports:
      - 9000
    volumes:
      - ./html:/var/www/example.com/html

In my host machine i use a path ex. ~/sites/example.com/html where i store my website's files. The php container needs permissions to write into these folders. These folders have been created by me in the host machine so they have my userid and my groupid. The php container has its own user and group (usually www-data). I am searching the most appropriate way to manage this inconvenience.

I was thought a way around but i think that it should be a better way to solve this. My way is to create a user www-data and a group www-data in my host machine setting it's number to 82. Same as www-data user of php container. Then i had to change every folder to chown www-data for group and make the folders 775 so the group can write to these folders.
The problems here are:

  1. I have to create user or change the user number if user exists. This is not possible in every host environment. For example, in my macOS i don't have user www-data and i am bit afraid to create one user just for this.
  2. I have to give group write permission. This is not preferable way in most of cms packages. For example prestashop cms proposes 755 permissions to folders.
@yosifkit
Copy link
Member

Since you are running fpm and thus port 9000 and not the reserved low port like 80 on Apache httpd, you can just add user: "1000:1000" to your compose yaml (substituting in your user and group id).

Related issue for php:apache #94 (comment)

@perarg
Copy link
Author

perarg commented Jan 29, 2018

Thank you @yosifkit. I think i get it. I use export UID and export GID="$(id -g $(whoami))" to get my host's uid and gid and as you propose i use user: $UID:$GID in my docker-compose.yml file.
As i read, the only issue still unsolved is that i have to export UID and GID every time. Except of writing in ~/.bashrc to take care of the above exports.

@perarg perarg closed this as completed Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants