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

File permission of output files is 'root:root' instead of the current user #51

Open
Youngerkind opened this issue Jan 9, 2025 · 2 comments

Comments

@Youngerkind
Copy link

The file permission is 'root:root' instead of the current user.
I have searched online, but I didn't find a safe and easy solution.

@bi-ran
Copy link
Collaborator

bi-ran commented Jan 20, 2025

you can consider using useradd and groupadd in the container to add a user with your uid and gid.

@Youngerkind
Copy link
Author

Youngerkind commented Feb 7, 2025

Thanks for @bi-ran 's reply. You inspired me a lot. I know that I am not alone.

For now, I modify the script ai2bmd. In the container, a dummy user which has exactly the same uid and gid as the current user will be created. Thus the output files' permissions will belong to the current user.

    #launch_cmd = f"docker run -w {docker_cwd} {cat(gpu_opts)} --rm {cat(mount_opts)} {_docker_image} python -u /ai2bmd/main.py {cat(argv)}"
    #===========================================================================
    import grp
    """
    I add those lines to recover the file permissions, 
    from "root:root" to "{uid}:{gid}"
    """
    uid = os.getuid()
    uname = os.getlogin()
    gid = os.getgid()
    gname = grp.getgrgid(gid).gr_name
    launch_cmd = f"docker run -w {docker_cwd} {cat(gpu_opts)} --rm {cat(mount_opts)} {_docker_image} sh -c \
'groupadd -g {gid} {gname} && useradd -u {uid} -g {gid} -m {uname} && su {uname} -c \
\"/opt/conda/bin/python -u /ai2bmd/main.py {cat(argv)}\"'"   #===========================================================================

Maybe it's a better to generate a new container image with the current user created in advance. However, I am not familiar with docker, so I decide to use this modified script.

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

No branches or pull requests

2 participants