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

Add initial_user traitlet to change user that container is started with #492

Closed
wants to merge 1 commit into from

Conversation

matthewwiese
Copy link
Contributor

This PR adds the initial_user traitlet, which may be used to change the user that the spawned container is started with.

Per my comment here I was encountering a mounted directory with root permissions that meant the default jovyan user had no access.

In order to follow the suggestion here, I needed DockerSpawner to start the container as root so that the permissions may be changed. This can be done via this traitlet like so:

c.DockerSpawner.initial_user = "root"

This PR is inspired by this comment, which I saw was not yet implemented. It is useful beyond my specific case, such as when changing user-related configuration in a Jupyter Docker Stack

@welcome
Copy link

welcome bot commented Jul 28, 2023

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@matthewwiese
Copy link
Contributor Author

I have discovered that this can just be done via the existing extra_create_kwargs:

c.DockerSpawner.extra_create_kwargs = {
    "user": "root"
}

I can close this PR as it's superfluous given the above knowledge.

Related: tests/test_dockerspawner.py::test_post_start fails for this PR because there is no jovyan user in the busybox:1.29.1 image.

@manics
Copy link
Member

manics commented Jul 29, 2023

I think extra_create_kwargs is a good solution, especially since if you add a user config it should also allow a numeric UID, and it should default to the containers default.

Do you think it'd be useful to add this as an example in the documentation?

@matthewwiese
Copy link
Contributor Author

Do you think it'd be useful to add this as an example in the documentation?

Yeah, I think an example in the docs would be handy, if only to increase the visibility of extra_create_kwargs. When I was investigating the problem that lead to this PR, I had read the entry for extra_create_kwargs in the API reference but it didn't immediately dawn on me how it may be useful.

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.

2 participants