Docker-stacks: Changing UID/GID of user causes large dockers images

Created on 9 Aug 2019  路  1Comment  路  Source: jupyter/docker-stacks

Hello everyone!

I'm using the jupyter/base-notebook image when spawning with JHub. Thanks for the capability to change user name, uid and gid!
It seems that using usermod in the start.sh have an impact on the containers space usage.
I think this is related with a known unresolved bug of Docker with sparse file detailed here: https://github.com/moby/moby/issues/5419
Using useradd or usermod modifies logs sparse files, not well handled by docker.

There is a workaround for the useradd command, using the -l option to prevent writing the log files causing the trouble. But I can't see a similar option in the usermod command.

You will find a screenshot of multiple tries made with JHub and a DummyAuthenticator allowing me to test various UIDs. In that example I'm using the NB_USER to also set both NB_UID and NB_GID as well.
Jupyter docker-stacks - UID bug

We clearly see a direct correlation.
Could anyone confirm this issue?

Thanks in advance!

Most helpful comment

Replacing the code dealing with uid and gid changes with the following code did the trick:

    # Change UID:GID of NB_USER to NB_UID:NB_GID if it does not match
    if [ "$NB_UID" != $(id -u $NB_USER) ] || [ "$NB_GID" != $(id -g $NB_USER) ] ; then
        echo "Set user $NB_USER UID:GID to: $NB_UID:$NB_GID"
        userdel $NB_USER
        groupadd -g $NB_GID -o ${NB_GROUP:-${NB_USER}}
        useradd --home /home/$USER -u $NB_UID -g $NB_GID -G 100 -l $NB_USER
    fi

See the following screenshot:
Jupyter docker-stacks - UID bug resolved

>All comments

Replacing the code dealing with uid and gid changes with the following code did the trick:

    # Change UID:GID of NB_USER to NB_UID:NB_GID if it does not match
    if [ "$NB_UID" != $(id -u $NB_USER) ] || [ "$NB_GID" != $(id -g $NB_USER) ] ; then
        echo "Set user $NB_USER UID:GID to: $NB_UID:$NB_GID"
        userdel $NB_USER
        groupadd -g $NB_GID -o ${NB_GROUP:-${NB_USER}}
        useradd --home /home/$USER -u $NB_UID -g $NB_GID -G 100 -l $NB_USER
    fi

See the following screenshot:
Jupyter docker-stacks - UID bug resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sgloutnikov picture sgloutnikov  路  4Comments

fyears picture fyears  路  5Comments

statiksof picture statiksof  路  4Comments

romainx picture romainx  路  4Comments

osobh picture osobh  路  3Comments