在Docker中的根用户和非根用户之间切换 [英] Switching Between Root and Non-Root Users in Docker

查看:475
本文介绍了在Docker中的根用户和非根用户之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试在Minikube上部署Django应用.但是在其中一个容器中,该映像要求我进入root来执行某些任务,然后切换postgres用户以创建一些数据库,然后切换回root来运行更多命令.

So I'm trying to deploy a Django app on Minikube. But in one of the containers, the image requires me to be in root for certain tasks and then switch the postgres user to create some databases and then switch back to root to run more commands.

我知道我可以为Docker使用USER功能,但是根据我所在的用户,它会搞乱某些任务.我也尝试过运行su - postgres,但是返回一条错误消息,指出命令必须是从终端.

I know I can use the USER functionality for Docker but that messes up certain task depending on what user I'm in. I have also tried running su - postgres but that returns an error saying that the command has to be from the terminal.

关于如何解决此问题的任何想法?

Any thoughts on how to fix this?

推荐答案

用于此目的的典型工具是 gosu .当包含在容器中时,您将运行gosu postgres $cmd,其中命令是您需要运行的任何内容.如果这是您唯一需要在入口点脚本结尾处在容器中运行的命令,则您将选择exec gosu postgres $cmd. gosu页面包含您使用其工具的原因的详细信息,主要原因是TTY和信号处理.请注意,他们的自述文件的末尾还列出了其他一些值得考虑的替代方案.

The typical tool for this in is gosu. When included in your container, you'd run gosu postgres $cmd where the command is whatever you need to run. If it's the only command you need to have running in the container at the end of your entrypoint script, then you'd exec gosu postgres $cmd. The gosu page includes details of why you'd use their tool, the main reasons being TTY and signal handling. Note the end of their readme also lists a few other alternatives which are worth considering.

这篇关于在Docker中的根用户和非根用户之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆