Skip to content
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

Introduce a new rayleigh-devel container to fix UID mapping issues #292

Merged
merged 14 commits into from
Oct 26, 2021

Conversation

tukss
Copy link
Contributor

@tukss tukss commented May 27, 2021

This uses the buildenv as a basis, but creates a user in the container
to make sure the UID/GID in the mounted home directory matches with the
user in the container. Before that files the container created files
owned by root on Linux host systems.

There is an alternative using the bindfs FUSE filesystem, but that comes with a host of other problems involving the use of FUSE inside a container.

For the commands in the documentation to work we still need to upload this new container to the geodynamics Docker hub account. For testing you can just build the container yourself.

It would be good if people could if this still works on macOS and Windows.

Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. To make testing easier I have build and pushed the new docker image to the geodynamics docker hub already. But I agree I would like to see someone using MacOS and Windows testing this before we merge it.

@gassmoeller
Copy link
Member

I noticed a few small problems:

  • This container can now only run with exactly the parameters provided (otherwise creating the user fails, or adding the directory fails and then the new user has no permission to write anywhere). Not sure we can do something about this, but it should be fine, users should follow the instructions.
  • Somehow we loose the environment variables that are specified in the base image. I do not know if that is because derived containers do not respect them in general, or if it is because of the new user, but the default configure does not find the fortran compiler anymore. Do we need to replicate the ENV commands of the base image, or do you have a different idea for how to fix this?

@tukss
Copy link
Contributor Author

tukss commented May 28, 2021

I tried to fix all the points. There is now a script ./docker-devel in the main directory to launch the container.
@cianwilson it would be great if you could give this a spin on macOS and Windows.

@cianwilson cianwilson self-requested a review May 28, 2021 21:31
@cianwilson
Copy link
Member

I haven't had time to look at these results in detail but here's what I get on various machines (spread out over multiple comments so I can copy and paste).

On ubuntu focal:

cwilson@fodhuchtu:rayleigh.master$ ./docker-devel 
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Already exists 
d2e110be24e1: Already exists 
889a7173dcfe: Already exists 
b91bf81b1866: Already exists 
59c90e480486: Pull complete 
a14be670e52b: Pull complete 
7aa0eb29b065: Pull complete 
ec6e80e59219: Pull complete 
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: invalid group ID 'cwilson'
useradd: invalid user ID '-g'
No passwd entry for user 'cwilson'
cwilson@fodhuchtu:rayleigh.master$

and I don't get put into a docker container at all, which is odd as if I then run:

cwilson@fodhuchtu:rayleigh.master$ docker run -it --rm -v $HOME:/work -e HOSTUID=$UID -e HOSTGID=$GROUPS -e HOSTUSER=$USER geodynamics/rayleigh-devel-bionic:latest
cwilson@7505f1688bac:~$

I am in the docker container and all looks good.

@cianwilson
Copy link
Member

On my mac (macOS 10.15 Catalina), I get:

cwilson@so-ghalaithe:rayleigh.master$ ./docker-devel 
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Already exists 
d2e110be24e1: Already exists 
889a7173dcfe: Already exists 
b91bf81b1866: Already exists 
59c90e480486: Pull complete 
a14be670e52b: Pull complete 
7aa0eb29b065: Pull complete 
ec6e80e59219: Pull complete 
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: GID '20' already exists
-su: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
cwilson@0e689db1a828:~$ 

So some warnings/errors and something presumably related to my .bashrc that docker is now trying to interpret because we've mounted all of $HOME. But I do at least end up in a running docker container.

@tukss
Copy link
Contributor Author

tukss commented May 28, 2021

I haven't had time to look at these results in detail but here's what I get on various machines (spread out over multiple comments so I can copy and paste).

On ubuntu focal:

cwilson@fodhuchtu:rayleigh.master$ ./docker-devel 
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Already exists 
d2e110be24e1: Already exists 
889a7173dcfe: Already exists 
b91bf81b1866: Already exists 
59c90e480486: Pull complete 
a14be670e52b: Pull complete 
7aa0eb29b065: Pull complete 
ec6e80e59219: Pull complete 
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: invalid group ID 'cwilson'
useradd: invalid user ID '-g'
No passwd entry for user 'cwilson'
cwilson@fodhuchtu:rayleigh.master$

and I don't get put into a docker container at all, which is odd as if I then run:

cwilson@fodhuchtu:rayleigh.master$ docker run -it --rm -v $HOME:/work -e HOSTUID=$UID -e HOSTGID=$GROUPS -e HOSTUSER=$USER geodynamics/rayleigh-devel-bionic:latest
cwilson@7505f1688bac:~$

I am in the docker container and all looks good.

It looks like the environment variables UID and GID are somehow not exported to the script being run. It might be because /bin/sh is bash on my RHEL system here and dash on your Ubuntu system. I changed the script to use the id command instead.

@tukss
Copy link
Contributor Author

tukss commented May 28, 2021

On my mac (macOS 10.15 Catalina), I get:

cwilson@so-ghalaithe:rayleigh.master$ ./docker-devel 
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Already exists 
d2e110be24e1: Already exists 
889a7173dcfe: Already exists 
b91bf81b1866: Already exists 
59c90e480486: Pull complete 
a14be670e52b: Pull complete 
7aa0eb29b065: Pull complete 
ec6e80e59219: Pull complete 
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: GID '20' already exists
-su: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
cwilson@0e689db1a828:~$ 

So some warnings/errors and something presumably related to my .bashrc that docker is now trying to interpret because we've mounted all of $HOME. But I do at least end up in a running docker container.

The error occurs because the group exists already locally. This is because macOS uses low GIDs for the users, which are system GIDs on Linux. I changed the script to only create the group if it doesn't exist already.

@cianwilson
Copy link
Member

I haven't had time to look at these results in detail but here's what I get on various machines (spread out over multiple comments so I can copy and paste).
On ubuntu focal:

cwilson@fodhuchtu:rayleigh.master$ ./docker-devel 
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Already exists 
d2e110be24e1: Already exists 
889a7173dcfe: Already exists 
b91bf81b1866: Already exists 
59c90e480486: Pull complete 
a14be670e52b: Pull complete 
7aa0eb29b065: Pull complete 
ec6e80e59219: Pull complete 
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: invalid group ID 'cwilson'
useradd: invalid user ID '-g'
No passwd entry for user 'cwilson'
cwilson@fodhuchtu:rayleigh.master$

and I don't get put into a docker container at all, which is odd as if I then run:

cwilson@fodhuchtu:rayleigh.master$ docker run -it --rm -v $HOME:/work -e HOSTUID=$UID -e HOSTGID=$GROUPS -e HOSTUSER=$USER geodynamics/rayleigh-devel-bionic:latest
cwilson@7505f1688bac:~$

I am in the docker container and all looks good.

It looks like the environment variables UID and GID are somehow not exported to the script being run. It might be because /bin/sh is bash on my RHEL system here and dash on your Ubuntu system. I changed the script to use the id command instead.

Not sure if this is a sufficient test for that but this would suggest that isn't the reason:

cwilson@fodhuchtu:tmp$ cat test.sh
#!/bin/sh

echo $SHELL

cwilson@fodhuchtu:tmp$ ./test.sh 
/bin/bash

@cianwilson
Copy link
Member

Realize this is moving target now and I should pull the latest changes but I've just got the older version sort of working on windows.

Haven't worked out how to run the script directly yet so am just copying and pasting the command. One thing is clear so far - environment variables (especially HOME) need to be in curly brackets.

More on this when I figure out how to run it through the script.

@cianwilson
Copy link
Member

With curly brackets, copy and pasting the command, and an old version of this pr, I get (on windows 10 pro):

PS C:\Users\cwilson\rayleigh> docker run -it --rm -v ${HOME}:/work -e HOSTUID=${UID} -e HOSTGID=${GROUPS} -e HOSTUER=${USER} geodynamics/rayleigh-devel-bionic:latest
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Pull complete                                                                                                                  d2e110be24e1: Pull complete                                                                                                                  889a7173dcfe: Pull complete                                                                                                                  b91bf81b1866: Pull complete                                                                                                                  59c90e480486: Pull complete                                                                                                                  a14be670e52b: Pull complete                                                                                                                  7aa0eb29b065: Pull complete                                                                                                                  ec6e80e59219: Pull complete                                                                                                                  Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: option requires an argument -- 'g'
Usage: groupadd [options] GROUP

Options:
  -f, --force                   exit successfully if the group already exists,
                                and cancel -g if the GID is already used
  -g, --gid GID                 use GID for the new group
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              allow to create groups with duplicate
                                (non-unique) GID
  -p, --password PASSWORD       use this encrypted password for the new group
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
      --extrausers              Use the extra users database

useradd: invalid user ID '-g'
root@4fca1fab305b:~#                              

So I do at least seem to end up in the docker container.

@tukss
Copy link
Contributor Author

tukss commented May 28, 2021

With curly brackets, copy and pasting the command, and an old version of this pr, I get (on windows 10 pro):

PS C:\Users\cwilson\rayleigh> docker run -it --rm -v ${HOME}:/work -e HOSTUID=${UID} -e HOSTGID=${GROUPS} -e HOSTUER=${USER} geodynamics/rayleigh-devel-bionic:latest
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Pull complete                                                                                                                  d2e110be24e1: Pull complete                                                                                                                  889a7173dcfe: Pull complete                                                                                                                  b91bf81b1866: Pull complete                                                                                                                  59c90e480486: Pull complete                                                                                                                  a14be670e52b: Pull complete                                                                                                                  7aa0eb29b065: Pull complete                                                                                                                  ec6e80e59219: Pull complete                                                                                                                  Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: option requires an argument -- 'g'
Usage: groupadd [options] GROUP

Options:
  -f, --force                   exit successfully if the group already exists,
                                and cancel -g if the GID is already used
  -g, --gid GID                 use GID for the new group
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              allow to create groups with duplicate
                                (non-unique) GID
  -p, --password PASSWORD       use this encrypted password for the new group
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
      --extrausers              Use the extra users database

useradd: invalid user ID '-g'
root@4fca1fab305b:~#                              

So I do at least seem to end up in the docker container.

I don't know much about the PowerShell syntax, but be probably need a separate script for PS. Windows doesn't know the id command, so we need to do something else there. As Windows doesn't have any of these UID mapping issues in the first place, it might be best to just run the container as root like we did before.

@tukss
Copy link
Contributor Author

tukss commented May 28, 2021

I haven't had time to look at these results in detail but here's what I get on various machines (spread out over multiple comments so I can copy and paste).
On ubuntu focal:

cwilson@fodhuchtu:rayleigh.master$ ./docker-devel 
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Already exists 
d2e110be24e1: Already exists 
889a7173dcfe: Already exists 
b91bf81b1866: Already exists 
59c90e480486: Pull complete 
a14be670e52b: Pull complete 
7aa0eb29b065: Pull complete 
ec6e80e59219: Pull complete 
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: invalid group ID 'cwilson'
useradd: invalid user ID '-g'
No passwd entry for user 'cwilson'
cwilson@fodhuchtu:rayleigh.master$

and I don't get put into a docker container at all, which is odd as if I then run:

cwilson@fodhuchtu:rayleigh.master$ docker run -it --rm -v $HOME:/work -e HOSTUID=$UID -e HOSTGID=$GROUPS -e HOSTUSER=$USER geodynamics/rayleigh-devel-bionic:latest
cwilson@7505f1688bac:~$

I am in the docker container and all looks good.

It looks like the environment variables UID and GID are somehow not exported to the script being run. It might be because /bin/sh is bash on my RHEL system here and dash on your Ubuntu system. I changed the script to use the id command instead.

Not sure if this is a sufficient test for that but this would suggest that isn't the reason:

cwilson@fodhuchtu:tmp$ cat test.sh
#!/bin/sh

echo $SHELL

cwilson@fodhuchtu:tmp$ ./test.sh 
/bin/bash

OK, interesting. Does it work with the new version of the script calling id directly?

@cianwilson
Copy link
Member

Yes, that seems to work beautifully now on ubuntu. On mac I still get some errors caused by the docker container sourcing my .bash_profile or .bashrc, which may be a problem with mounting the entirety of $HOME more generally. I'm trying windows through a bash shell but still not having much luck there. It would be nice if it were possible to get the docker-devel script to recognize when id isn't available and then have it fall back on not setting the environment and launching as root as you suggested.

tukss added 9 commits June 2, 2021 16:14
This uses the buildenv as a basis, but creates a user in the container
to make sure the UID/GID in the mounted home directory matches with the
user in the container. Before that files the container created files
owned by root on Linux host systems.
This now displays a warning if the container is run without the necessary environemnt variables.
Containers apparently do not inherit the environment from their base containers.
This had a different behavior depending on the shell being used to call the
script.
In particular on macOS with low user GIDs the group might exist already.
This prevents warnings and errors on systems with incompatible commands in
~/.bashrc file.
@tukss tukss force-pushed the docker-uid-fix branch from e135e5f to 02a3960 Compare June 2, 2021 22:15
@tukss
Copy link
Contributor Author

tukss commented Jun 2, 2021

Yes, that seems to work beautifully now on ubuntu. On mac I still get some errors caused by the docker container sourcing my .bash_profile or .bashrc, which may be a problem with mounting the entirety of $HOME more generally. I'm trying windows through a bash shell but still not having much luck there. It would be nice if it were possible to get the docker-devel script to recognize when id isn't available and then have it fall back on not setting the environment and launching as root as you suggested.

The script is already doing that. It's just that the container on Docker Hub hasn't been updated to the latest version. If the any of the calls to ID doesn't work, the environment variable will be empty and the container will start as root, displaying a warning. Maybe you can build the container yourself for testing.

As to the errors caused by options in your .bashrc. I changed the entrypoint to prevent sourcing the file from the users home directory. This way we can still get access to the .ssh directory and the whole home by mounting it.

tukss added 3 commits June 2, 2021 16:21
This also add the NOUIDWARN option that suppressed the warning when
running as root in the container. This is not an issue on Windows, so
it is better not to confuse the users.
@tukss
Copy link
Contributor Author

tukss commented Jun 2, 2021

I added a batch script docker-devel.bat for Windows users. This also suppresses the warning when running as root.

@tukss
Copy link
Contributor Author

tukss commented Aug 17, 2021

Last time I checked all worked as expected for me. Maybe someone with a Windows system should give it another spin, especially the .bat file. I (fortunately) don't have a Windows laptop anymore.

@gassmoeller gassmoeller added this to the Rayleigh 1.0 milestone Sep 24, 2021
@cianwilson
Copy link
Member

Apologies for the long silence on this.

On linux (ubuntu 20.04 focal) this still works beautifully:

cwilson@fodhuchtu:rayleigh$ ./docker-devel
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Pull complete 
d2e110be24e1: Pull complete 
889a7173dcfe: Pull complete 
b91bf81b1866: Pull complete 
59c90e480486: Pull complete 
a14be670e52b: Pull complete 
7aa0eb29b065: Pull complete 
ec6e80e59219: Pull complete 
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
cwilson@c1684b3397a2:~$

On my mac (macOS 11.6 big sur) I still get an error about the group id (low numbers indeed... gid=20 and I end up in the group dialout) but it does still get me into a docker container:

cwilson@so-ghalaithe:rayleigh$ ./docker-devel
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Already exists
d2e110be24e1: Already exists
889a7173dcfe: Already exists
b91bf81b1866: Already exists
59c90e480486: Pull complete
a14be670e52b: Pull complete
7aa0eb29b065: Pull complete
ec6e80e59219: Pull complete
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
groupadd: GID '20' already exists
-su: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
cwilson@9cc6fb9ffe8c:~$

On windows (windows 10 pro, using power shell) I don't get in at all:

PS C:\Users\cwilson\rayleigh.docker-uid-fix> .\docker-devel.bat

C:\Users\cwilson\rayleigh.docker-uid-fix>docker run -it --rm -v $HOME:/work -e NOUIDWARN=1 geodynamics/rayleigh-devel-bionic:latest
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Pull complete                                                                                             
d2e110be24e1: Pull complete                                                                                             
889a7173dcfe: Pull complete                                                                                             
b91bf81b1866: Pull complete                                                                                             
59c90e480486: Pull complete                                                                                             
a14be670e52b: Pull complete                                                                                             
7aa0eb29b065: Pull complete                                                                                            
 ec6e80e59219: Pull complete                                                                                             
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
docker: Error response from daemon: create $HOME: "$HOME" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
PS C:\Users\cwilson\rayleigh.docker-uid-fix>

As linux is the main target of this -- docker desktop on macs already deals with uid issues and I'm not aware of any windows users -- I'd be happy to approve this if there aren't quick fixes. Though possibly then we should drop the .bat version in that case and be explicit that windows isn't really supported?

@feathern
Copy link
Contributor

I'm good with Cian's suggestion. Though to be fair, I ONLY use Docker in Windows :) That said, I'm still experimenting with a Rayleigh environment build.

@cianwilson
Copy link
Member

Ah, oops! Didn't know that :-)

Does .\docker-devel.bat work for you on your windows system @feathern ?

@tukss
Copy link
Contributor Author

tukss commented Sep 30, 2021

Just for clarification docker-devel.bat is a script for CMD.EXE not for PowerShell. CMD still uses the old DOS syntax and should be available on any system from Windows NT 3.5 onward or something like that.
Can you try running it with CMD.EXE? If needed we could also make a PowerShell script.

@cianwilson
Copy link
Member

Oh, I'm sorry @tukss , hadn't realized that.

Running in the command prompt I get the same error:

C:\Users\cwilson\rayleigh.docker-uid-fix>.\docker-devel.bat

C:\Users\cwilson\rayleigh.docker-uid-fix>docker run -it --rm -v ${HOME}:/work -e NOUIDWARN=1 geodynamics/rayleigh-devel-bionic:latest
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
4bbfd2c87b75: Pull complete                                                                                             
d2e110be24e1: Pull complete                                                                                             
889a7173dcfe: Pull complete                                                                                             
b91bf81b1866: Pull complete                                                                                             
59c90e480486: Pull complete                                                                                             
a14be670e52b: Pull complete                                                                                             
7aa0eb29b065: Pull complete                                                                                             
ec6e80e59219: Pull complete                                                                                             
Digest: sha256:30e8586a9d37bd98ed5a674e5e75caa624d65eb99aa1905849f8843ae5273d2e
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
docker: Error response from daemon: create $HOME: "$HOME" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.

@feathern
Copy link
Contributor

I'm a little rusty with Docker, so it might be a bit before I can try this out on my laptop. It's really only something I use in a pinch because this particular laptop isn't set up for dual boot. Unless @tukss can fix the .bat file, I think it would be fine to remove it for now and add Windows Docker support after 1.0.

@tukss
Copy link
Contributor Author

tukss commented Sep 30, 2021

Ah right. $HOME doesn't make any sense on Windows. I tried replacing it with %USERPROFILE%. Please give it a shot. I'm not completely sure about the Windows rules for handling spaces in variables and unfortunately spaces in usernames are a thing in the Windows world. Some built-in commands try to be clever, so that cd "foo bar" and cd foo bar are the same. Let's see how Docker handles this.

@cianwilson
Copy link
Member

Some progress there, I do now get into a docker container but I'm root and there's an error along the way regarding the group and user add commands...

C:\Users\cwilson\rayleigh.docker-uid-fix>.\docker-devel.bat

C:\Users\cwilson\rayleigh.docker-uid-fix>docker run -it --rm -v "C:\Users\cwilson":/work -e NOUIDWARN=1 geodynamics/rayleigh-devel-bionic:latest
groupadd: option requires an argument -- 'g'
Usage: groupadd [options] GROUP

Options:
  -f, --force                   exit successfully if the group already exists,
                                and cancel -g if the GID is already used
  -g, --gid GID                 use GID for the new group
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              allow to create groups with duplicate
                                (non-unique) GID
  -p, --password PASSWORD       use this encrypted password for the new group
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
      --extrausers              Use the extra users database

useradd: invalid user ID '-g'
root@c79b56b83797:~# pwd
/root
root@c79b56b83797:~# ls
root@c79b56b83797:~#

Similar story in both the command prompt and power shell.

@tukss
Copy link
Contributor Author

tukss commented Oct 1, 2021

Thanks for testing. Looking at the relevant entrypoint.sh it shouldn't even reach the code calling groupadd if HOSTGID, HOSTUSER, and HOSTUID aren't set. Could it be that you are running an older version of the Docker container from DockerHub? Can you build the current version from the Dockerfile in docker/rayleigh-devel-bionic? If it's that we just have to ask @gassmoeller to push the new version to DockerHub.

If the problem persists after rebuilding, please send me the output of echo $HOSTUID from inside the container.

@tukss
Copy link
Contributor Author

tukss commented Oct 1, 2021

On Windows the expected behavior is that you are root inside the container. That doesn't affect the UID of the files created in your home directory, so it shouldn't be a problem.

@tukss
Copy link
Contributor Author

tukss commented Oct 6, 2021

@cianwilson I don't want to rush you. Just checking if GitHub actually sent you my previous comments on this PR.

@cianwilson
Copy link
Member

No worries about rushing me. I could do with a little bit of that :-) I saw the comments just haven't had a chance to sit in front of that computer yet. Will do tonight. Thanks!

@cianwilson
Copy link
Member

Is the current version of the docker container you want me to build in this branch or should I build it off master?

Building off the one in this branch leads to an error. My complete workflow (in command prompt on windows):

C:\Users\cwilson\rayleigh.docker-uid-fix\docker\rayleigh-devel-bionic>docker build -t geodynamics/rayleigh-devel-bionic .
[+] Building 2880.6s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                               1.0s
 => => transferring dockerfile: 351B                                                                               0.0s
 => [internal] load .dockerignore                                                                                  1.2s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for docker.io/geodynamics/rayleigh-buildenv-bionic:latest                             1.6s
 => [internal] load build context                                                                                  1.0s
 => => transferring context: 1.16kB                                                                                0.1s
 => [1/3] FROM docker.io/geodynamics/rayleigh-buildenv-bionic@sha256:7813706470e4f02f505d1236df740b3dc9f27deaa  1650.7s
 => => resolve docker.io/geodynamics/rayleigh-buildenv-bionic@sha256:7813706470e4f02f505d1236df740b3dc9f27deaafba  0.4s
 => => sha256:7813706470e4f02f505d1236df740b3dc9f27deaafba611a4cc4f72a5d47e27c 1.17kB / 1.17kB                     0.0s
 => => sha256:cbb67d509c9f02c098f4f26cf9536bbd439fe612706b19883e5e92ceeb25c814 2.94kB / 2.94kB                     0.0s
 => => sha256:25fa05cd42bd8fabb25d2a6f3f8c9f7ab34637903d00fd2ed1c1d0fa980427dd 26.70MB / 26.70MB                 137.6s
 => => sha256:ca50a2a58e9b5c9ac455d9e77d54b6d03e8ca7537d910225df1eb01af6bc70f5 532.08MB / 532.08MB              1601.6s
 => => sha256:313cd7899171c3398346fd3a7504323b6dd24bbeae372f7a5feb233ae8281329 50.84MB / 50.84MB                 218.1s
 => => extracting sha256:25fa05cd42bd8fabb25d2a6f3f8c9f7ab34637903d00fd2ed1c1d0fa980427dd                          1.1s
 => => sha256:0c6644dfcd388fd6d6d0bd66df9dd2ec6c11458c59aec243f79aad39f4fd71e4 98.79MB / 98.79MB                 400.9s
 => => extracting sha256:ca50a2a58e9b5c9ac455d9e77d54b6d03e8ca7537d910225df1eb01af6bc70f5                         31.6s
 => => extracting sha256:313cd7899171c3398346fd3a7504323b6dd24bbeae372f7a5feb233ae8281329                          1.9s
 => => extracting sha256:0c6644dfcd388fd6d6d0bd66df9dd2ec6c11458c59aec243f79aad39f4fd71e4                          2.0s
 => [2/3] RUN apt update &&   DEBIAN_FRONTEND='noninteractive'   DEBCONF_NONINTERACTIVE_SEEN='true'   apt inst  1222.5s
 => [3/3] COPY /entrypoint.sh /entrypoint.sh                                                                       1.4s
 => exporting to image                                                                                             1.7s
 => => exporting layers                                                                                            1.3s
 => => writing image sha256:e3816857761fb9e540e253e17deee9acaae1747866babae2a424ac8aa340a2c4                       0.1s
 => => naming to docker.io/geodynamics/rayleigh-devel-bionic                                                       0.1s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

C:\Users\cwilson\rayleigh.docker-uid-fix\docker\rayleigh-devel-bionic>docker image ls
REPOSITORY                          TAG       IMAGE ID       CREATED       SIZE
geodynamics/rayleigh-devel-bionic   latest    e3816857761f   5 hours ago   1.8GB

C:\Users\cwilson\rayleigh.docker-uid-fix\docker\rayleigh-devel-bionic>cd ../../

C:\Users\cwilson\rayleigh.docker-uid-fix>.\docker-devel.bat

C:\Users\cwilson\rayleigh.docker-uid-fix>docker run -it --rm -v "C:\Users\cwilson":/work -e NOUIDWARN=1 geodynamics/rayleigh-devel-bionic:latest
/bin/sh: 1: /entrypoint.sh: not found

C:\Users\cwilson\rayleigh.docker-uid-fix>git log -n1
commit 0149f52944e0337d5157b4600750bc9bc736409a (HEAD -> docker-uid-fix, origin/docker-uid-fix)
Author: Philipp Edelmann <[email protected]>
Date:   Thu Sep 30 12:47:09 2021 -0600

    fix environment variable in Windows batch script

C:\Users\cwilson\rayleigh.docker-uid-fix>

I confirmed that that docker build worked on an ubuntu box.

@cianwilson
Copy link
Member

Scratch that. I see there is no docker/rayleigh-devel-bionic folder in master.

@tukss
Copy link
Contributor Author

tukss commented Oct 11, 2021

OK. That is really strange. It tells us entrypoint.sh doesn't exist, but we see it copying it there. I'll build the image here and push it to DockerHub. I'm curious to see if the same problem occurs.

@tukss
Copy link
Contributor Author

tukss commented Oct 12, 2021

Can you try running it like this?
docker run -it --rm -v "%USERPROFILE%":/work -e NOUIDWARN=1 tuks/rayleigh-devel-bionic:latest

Effectively you're replacing geodynamics with my repo (tuks) in the .bat file.

If this works, then it's just the build process on Windows, that's broken.

@cianwilson
Copy link
Member

Yup, looks like that worked...

C:\Users\cwilson\rayleigh.docker-uid-fix>git diff
diff --git a/docker-devel.bat b/docker-devel.bat
index 49287fe..37ef642 100755
--- a/docker-devel.bat
+++ b/docker-devel.bat
@@ -1,3 +1,3 @@
 :: echo off

-docker run -it --rm -v "%USERPROFILE%":/work -e NOUIDWARN=1 geodynamics/rayleigh-devel-bionic:latest
+docker run -it --rm -v "%USERPROFILE%":/work -e NOUIDWARN=1 tuks/rayleigh-devel-bionic:latest

C:\Users\cwilson\rayleigh.docker-uid-fix>.\docker-devel.bat

C:\Users\cwilson\rayleigh.docker-uid-fix>docker run -it --rm -v "C:\Users\cwilson":/work -e NOUIDWARN=1 tuks/rayleigh-devel-bionic:latest
Unable to find image 'tuks/rayleigh-devel-bionic:latest' locally
latest: Pulling from tuks/rayleigh-devel-bionic
25fa05cd42bd: Already exists                                                                                            ca50a2a58e9b: Already exists                                                                                            313cd7899171: Already exists                                                                                            0c6644dfcd38: Already exists                                                                                            96faa9ea75f5: Pull complete                                                                                             5fa7e3089a82: Pull complete                                                                                             Digest: sha256:ba2490f2857680e8b4509990d22861d7fd1ef72f7232b3c364b35fe9dcda1387
Status: Downloaded newer image for tuks/rayleigh-devel-bionic:latest
root@29428aa84e96:~#

So, a new docker image just needs to be built and pushed to dockerhub?

@tukss
Copy link
Contributor Author

tukss commented Oct 12, 2021

Yes, I think pushing the new image will solve the problem.

And independently of this PR we should find out why the build on Windows doesn't include the entrypoint.sh. Maybe it doesn't like the slashes in the command.

@cianwilson
Copy link
Member

Great! Happy to test again when that happens but will be offline for a few days until at least next week.

@tukss
Copy link
Contributor Author

tukss commented Oct 14, 2021

@gassmoeller What's our normal procedure here? Do we first merge to master and update the image on Docker Hub then or the other way round? Thank you!

@gassmoeller
Copy link
Member

The order doesnt really matter in this case. Ultimately we want to set it up to build the image automatically once a PR is merged. For now I have built it locally and pushed to geodynamics/rayleigh-devel-bionic. Give it a try and let me know.

@cianwilson
Copy link
Member

Yup, that seems to work now...

C:\Users\cwilson\rayleigh.docker-uid-fix>.\docker-devel.bat

C:\Users\cwilson\rayleigh.docker-uid-fix>docker run -it --rm -v "C:\Users\cwilson":/work -e NOUIDWARN=1 geodynamics/rayleigh-devel-bionic:latest
Unable to find image 'geodynamics/rayleigh-devel-bionic:latest' locally
latest: Pulling from geodynamics/rayleigh-devel-bionic
25fa05cd42bd: Pull complete                                                                                             ca50a2a58e9b: Pull complete                                                                                             313cd7899171: Pull complete                                                                                             0c6644dfcd38: Pull complete                                                                                             c95827cb0c64: Pull complete                                                                                             2d711afdc624: Pull complete                                                                                             Digest: sha256:b1f920422fc36a75dbc504fd31117115190d46f518e6760ac399a36e138f6fa9
Status: Downloaded newer image for geodynamics/rayleigh-devel-bionic:latest
root@f311cb7433a3:~#             

Thanks @gassmoeller and @tukss !

Copy link
Member

@cianwilson cianwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@cianwilson cianwilson merged commit 2eb52eb into geodynamics:master Oct 26, 2021
@tukss tukss deleted the docker-uid-fix branch October 29, 2021 16:31
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.

4 participants