Skip to content

Add node group/user with gid/uid 1000 and a home directory - #263

Merged
pesho merged 1 commit into
nodejs:masterfrom
blueimp:master
Nov 18, 2016
Merged

pesho merged 1 commit into
nodejs:masterfrom
blueimp:master

Conversation

@blueimp

@blueimp blueimp commented Nov 7, 2016

Copy link
Copy Markdown
Contributor

This is a workaround for docker-machine/boot2docker issue 581, see
boot2docker/boot2docker#581
Although Docker for Mac/Windows doesn't have this issue, there are still many developers using docker-machine with VirtualBox+NFS for performance reasons.

Using a normal user with a home directory instead of a system user faciliates usage of the docker images as e.g. installing packages can simply done in the home directory.

pesho

This comment was marked as off-topic.

@Pamplemousse

Pamplemousse commented Nov 13, 2016 •

Copy link
Copy Markdown

Hi guys,

I am interested in this as I have a similar solution to fix rights on files generated inside a container (e.g node_modules readable from a non-root user on host ).

I favored using an entrypoint to create the necessary user, which allows me to pass uid and gid as an environment variable in the docker run.

My solution does not work yet for every scenarii that I have (see above, note that current -u node option fails on npm install as well). This is what it looks like so far:

#!/bin/bash
user=$(whoami)

if [ $user != "root" ]; then
    cat >&2 <<-EOINFO
    INFO: A user has been specified. Default root is
    needed in order to perform group and user ids
    modifications.
    Do NOT use "-u <username>" in "docker run".
    ****************************************************
EOINFO

else
    username="robert_paulson"

    if [ "$USER_ID" ]; then
        uid="$USER_ID"
    else
        cat >&2 <<-'EOINFO'
        INFO: No uid as been specified, 1000 will be used by
        default.
        Use "-e USER_ID=1042" to set it in "docker run".
        ****************************************************
EOINFO

        uid=1000
    fi

    if [ "$GROUP_ID" ]; then
        gid="$GROUP_ID"
    else
        cat >&2 <<-'EOINFO'
        INFO: No gid as been specified, 1000 will be used by
        default.
        Use "-e GROUP_ID=1042" to set it in "docker run".
        ****************************************************
EOINFO

        gid=1000
    fi

    groupadd -g $gid $username
    useradd -u $uid -g $gid -G node --create-home $username
fi

su -c "$@" $username

EDIT

The problem was in the way I called docker run. It seems to be working now ; not extensively tested though.

Here are my implementation (Dockerfile, and entrypoint), and some code using it.

Hope this can be useful.

@SimenB

SimenB commented Nov 14, 2016

Copy link
Copy Markdown
Member

I'd like /home/node to exist, would a patch for just that be accepted?

pesho

This comment was marked as off-topic.

@LaurentGoderre

Copy link
Copy Markdown
Member

Could you update the alpine variant as well?

@blueimp

blueimp commented Nov 14, 2016

Copy link
Copy Markdown
Contributor Author

@LaurentGoderre I've added the same change to the Alpine variant.
@pesho Please review once more.

@pesho

pesho commented Nov 15, 2016

Copy link
Copy Markdown
Contributor

Not sure about the Alpine change, I'm not very familiar with it. Can another @nodejs/docker member please take a look as well?

@LaurentGoderre

Copy link
Copy Markdown
Member

@SimenB there's a discussion about that in #270

@pesho

pesho commented Nov 15, 2016

Copy link
Copy Markdown
Contributor

Actually @blueimp can you please make one more change? Currently the added user (on the non-Alpine variants) has the shell set to /bin/sh which resolves to Dash, which is not as comfortable as Bash when used as a login shell. Setting the shell to /bin/bash (which is already available in the images) would be more user-friendly.

(This does not apply to the Alpine variant, as its shell is provided by Busybox)

@blueimp

blueimp commented Nov 15, 2016

Copy link
Copy Markdown
Contributor Author

@pesho done. :)

SimenB

This comment was marked as off-topic.

@LaurentGoderre

Copy link
Copy Markdown
Member

This is awesome!!

Starefossen

This comment was marked as off-topic.

@blueimp

blueimp commented Nov 15, 2016

Copy link
Copy Markdown
Contributor Author

Sorry @Starefossen , @SimenB just noticed one line which is uneccessary, so I'll do one new commit.

@blueimp

blueimp commented Nov 15, 2016

Copy link
Copy Markdown
Contributor Author

Done.

@chorrell

Copy link
Copy Markdown
Contributor

It looks like this is good to be merged.

@nodejs/docker Any objections?

chorrell

This comment was marked as off-topic.

@LaurentGoderre

Copy link
Copy Markdown
Member

👍

@pesho

pesho commented Nov 18, 2016 •

Copy link
Copy Markdown
Contributor

Merging as there have been 4 approvals and no objections so far.

@pesho
pesho merged commit 5fab0fc into nodejs:master Nov 18, 2016
@pesho

pesho commented Nov 18, 2016

Copy link
Copy Markdown
Contributor

I think we should wait until the next Node.js tagged release to push this into the Docker library, as it could break some images which already use the node user (due to the UID change).

@chorrell

Copy link
Copy Markdown
Contributor

Sounds good. I'll do it as part of the v7.2.0 release.

@Risto-Stevcev

Copy link
Copy Markdown

This merge and #261 broke the functionality in my gyeh/purescript containers on docker hub. Before, you could do something like docker run --rm -itv $(pwd):/home/pureuser/src gyeh/purescript:0.10.1 bash. But now if you do that then the owner of the mounted /home/pureuser/src folder will be node instead of pureuser, which effectively breaks the functionality of the container.

I filed a ticket for this at the docker repo, but I just thought I should mention this as a heads up as this could be a problem for users relying on similar functionality when composing this container.

@chorrell

Copy link
Copy Markdown
Contributor

Hi @Risto-Stevcev

We're tracking that here: #289

Pamplemousse pushed a commit to Pamplemousse/xaviermaso.com that referenced this pull request Jan 3, 2017
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

Successfully merging this pull request may close these issues.

8 participants