Skip to content

Build docker container with ready to use user env

Jeremy Soller requested to merge fengalin:docker_user_env into master

Created by: fengalin

Problem: In order to initialize the user with an id matching the host's user id, a -e LOCAL_USER_ID argument is passed to the run command. The entrypoint.sh script is then in charge of creating the user and changing ownership on cargo and rustup directories. Finally, gosu runs the requested command (make all) as user. This strategy allows adapting the container to the environment of the running user. This is needed as we bind redox source tree to the container and need read/write access to it. However, every time the container is run, the user creation and chown -R are executed.

Solution: Pass --build-arg to the container build command in order to create the user at container build time. Then, everything can be installed like a local host user would. In order to preserve the ability to adapt the container to the environment of the running user, the host's user id must be checked at run time and the container user id changed when necessary. Take this opportunity to adapt the group id.

Changes introduced by this pull request:

  • Move user environment creation from entrypoint.sh to Dockerfile.
  • Change user id and group id if necessary.
  • apt-get update all the repos only once. Update redox repo individually.
  • Add user to the list of sudoers.
  • Use default user directories for cargo and rust.
  • Bind the source tree to the user's ~/src. Run command uses /home/user/src/ instead of /src. See README.md.
  • Update README.md: update submodule sync step to avoid a dependency on cargo.
  • Update README.md: use make update all to update cargo's environment in the container.

Constraint: x86-64-elf-redox-* packages use apt-transport-https, so redox.list must be added after the first apt-get install.

State: Tested on Fedora 26 only.

Merge request reports