在我的设置文件中,我得到了这样的环境变量
'NAME': os.environ['PG_DBNAME'], # Database
我正在像这样在 docker 文件中设置
-e PG_DBNAME= "mapp"
现在
- 网络应用运行良好
- 如果我通过
docker exec ... bash
登录到 shell,那么 env 变量也会被设置
但是如果我通过 ssh 客户端的 ipaddress 和端口号登录,那么我可以登录但未设置 env 变量
最佳答案
正如 issue 2569 中的评论:
This is expected. SSH wipes out the environment as part of the login process.
One way to work around it is to dump the environment variables in
/etc/environment
(e.g.env | grep _ >> /etc/environment
) before starting Supervisor.
Further "login processes" should source this file, and tada! There is your environment.
那个env | grep _ >>/etc/environment
可能是与您的图像关联(通过 ENTRYPOINT
或 CMD
)的默认运行脚本的一部分。
Daniel A.A. Pelsmaeker建议jenkinsci/docker-ssh-agent
issue 33对于选择和设置除特定拒绝名单之外的所有环境变量的方法:
For my own uses I changed that line to the following:
env | egrep -v "^(HOME=|USER=|MAIL=|LC_ALL=|LS_COLORS=|LANG=|HOSTNAME=|PWD=|TERM=|SHLVL=|LANGUAGE=|_=)" >> /etc/environment
This takes all environment variables, except those listed, and appends then to /etc/environment, overriding any previously defined there.
关于django - 通过 shell 记录时未设置 Docker 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34630571/