Skip to content
This repository has been archived by the owner on Mar 13, 2019. It is now read-only.

Permissions #35

Open
renatomefi opened this issue Feb 8, 2016 · 13 comments
Open

Permissions #35

renatomefi opened this issue Feb 8, 2016 · 13 comments

Comments

@renatomefi
Copy link

Hello,

If I use composer without changing any settings my vendor will get root:root 755 permissions.
If I use my own UID for user and/or group it will fail on writing into the cache.

Am I doing something wrong or is this the expected behaviour?

@RobLoach
Copy link
Owner

RobLoach commented Mar 3, 2016

Could you post your workflow to get the permission error?

@fesor
Copy link

fesor commented Apr 4, 2016

@RobLoach here is my workaround:

FROM composer/composer:php7

RUN git config --system user.name "Docker" && \
    git config --system user.email "docker <at> localhost"

ENV COMPOSER_HOME="/composer"

And here how I use it:

docker run --rm -it \
     --user $(id -u) \
     -v $(pwd):/app \
     -v ~/.composer:/composer \
     fesor/composer $@

This solves:

  • issues of permissions, since container is running from current user
  • git issues, which fails to clone repo is no such user exists in /etc/passwd
  • make use of cache and composer configs, since it uses user's configs and cache via volumes

@renatomefi
Copy link
Author

@RobLoach its exactly as @fesor showed, I'm using your image as a volatile container with --rm option.
Still its a lot of "hack" to use this solution, mainly because you have to set git user.

Have you see this approach: https://github.com/eXistenZNL/Docker-Composer ?

It seems pretty effect for this kind of usage!

Thank you

@RobLoach
Copy link
Owner

RobLoach commented Apr 6, 2016

That sounds like a great solution. So, in summary, we should:

  1. Add the following to the Dockerfile base:

    RUN git config --system user.name "Docker" && \
    git config --system user.email "docker <at> localhost"
    
  2. Update usage documentation to:

    docker run --rm -it \
       --user $(id -u) \
       -v $(pwd):/app \
       -v ~/.composer:/composer \
       composer/composer $@
    
  3. Switch COMPOSER_HOME to /composer

@fesor
Copy link

fesor commented Apr 9, 2016

@RobLoach yep, the only case that could go wrong is handling of private repositories. Will to check this.

@dagomar
Copy link

dagomar commented May 1, 2016

I'm using this solution, will this be part of the official build??

[edit]
I notice that this creates files as current user, but group root, correct? I found this can be solved by doing:

    docker run --rm -it \
    --user $(id -u):$(id -u) \
    -v $(pwd):/app \
    -v ~/.composer:/composer \
    composer/composer $@

@roverwolf
Copy link

The second $(id -u) in the previous comment should probably be $(id -g) to get the group id.

In order to get rid of the fatal: unable to look up current user in the passwd file: no such user error from git when it needs to clone a repo I've found I need to add:

    -v /etc/passwd:/etc/passwd

@fesor
Copy link

fesor commented Aug 10, 2016

@roverwolf, I solve this just by adding user in git config:

RUN git config --system user.name "Docker" \
   && git config --system user.email "docker <at> localhost"

This solves this issue

@roverwolf
Copy link

@fesor, I tried running the git config commands in my Dockerfile, but it did not seem to work. I'll try again as I may have misconfigured something along the way.

Bind mounting /etc/passwd (or a subset of it) into the container is another option for anyone running into the issue if setting the user name and email doesn't work for them.

@llernestal
Copy link

To get the container working with my private repositories I used this:

docker run -it --rm \
--user $(id -u):$(id -g) \
-v $(pwd):/app \
-v ~/.composer:/composer \
-v /etc/passwd:/etc/passwd \
-v ~/.ssh:$HOME/.ssh \
composer/composer $@

@toby-griffiths
Copy link

I'm using the following command, which works OK…

docker run --rm --user $(id -u):$(id -g) -v $(pwd):/app composer/composer install

… but I get the warning…

Cannot create cache directory /composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /composer/cache/files/, or directory is not writable. Proceeding without cache

Any ideas how to get around this?

@llernestal
Copy link

@toby-griffiths, Try adding -v ~/.composer:/composer to your command

@toby-griffiths
Copy link

@llernestal Thanks :o)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants