dockerfile构建镜像
docker-compose运行容器
supervisor进程管理
部署过程中,想通过在宿主机上设置环境变量,容器获取宿主机的环境变量,服务使用环境变量启动
首先想到的是通过docker-compose.yml文件中的environment标签,将宿主机的环境变量传入容器中
# docker-compose.yml
version: "3.8"
services:
service:
...
environment:
- requestSecret=$requestSecret
- username=$username
- password=$password
结果也确实传入容器中了,但supervisor启动的服务并没有获取到环境变量
这是因为
Subprocesses will inherit the environment of the shell used to start the supervisord program. Several environment variables will be set by supervisord itself in the child’s environment also, including SUPERVISOR_ENABLED (a flag indicating the process is under supervisor control), SUPERVISOR_PROCESS_NAME (the config-file-specified process name for this process) and SUPERVISOR_GROUP_NAME (the config-file-specified process group name for the child pro

本文探讨了在Docker环境中通过docker-compose将宿主机环境变量传递给容器,并确保这些变量能在Supervisor进程中生效的过程。作者遇到的问题是,尽管环境变量已传入容器,但Supervisor管理的服务无法获取到这些变量。解决方案是在docker-compose.yml中通过命令行设置环境变量,然后在Dockerfile中使用ARG并在ENTRYPOINT或CMD中执行命令。最终,通过修改docker-compose.yml的command字段,成功实现了环境变量的传递并被Supervisor服务使用。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



