Running a bash script before startup in an NGINX docker container(在 NGINX docker 容器中启动之前运行 bash 脚本)
问题描述
我正在尝试使用 docker 在 localhost:8000 上运行 javascript 应用程序.我想做的一部分是根据 docker run 命令换出一些配置文件,我想将环境变量传递到容器中,以便 bash 脚本可以将其用作参数.
I'm trying to run a javascript app on localhost:8000 using docker. Part of what I would like to do is swap out some config files based on the docker run command, I'd like to pass an environment variable into the container so that the bash script can use that as a parameter.
我的 dockerfile 是这样的:
What my dockerfile is looking like is this:
FROM nginx
COPY . /usr/share/nginx/html
CMD ["bash","/usr/share/nginx/html/runfile.sh"]
bash 脚本如下所示:
And the bash script looks like this:
#!/bin/bash
if [ "$SECURITY_VERSION" = "OPENAM" ]; then
sed -i -e 's/localhost/openam/g' authConfig.js
fi
docker run -p 8000:80 missioncontrol:latest -e SECURITY_VERSION="TEST"
Docker 给我一个异常说 -e exec command not found.
Docker gives me an exception saying -e exec command not found.
但是,如果我将 dockerfile 更改为使用 ENTRYPOINT 而不是 CMD,则 -e 标志有效,但网络服务器无法启动.
However if I change the dockerfile to use ENTRYPOINT instead of CMD, the -e flag works but the webserver does not start up.
这里有什么我遗漏的吗?ENTRYPOINT 是被覆盖还是什么?
Is there something I'm missing here? Is the ENTRYPOINT being overriden or something?
所以我更新了我的 dockerfile 以使用 ENTRYPOINT ["bash","/usr/share/nginx/html/runfile.sh", ";", " nginx -g daemon off;"]代码>
So I've updated my dockerfile to use ENTRYPOINT ["bash","/usr/share/nginx/html/runfile.sh", ";", " nginx -g daemon off;"]
但是 docker 容器仍然关闭.我有什么遗漏吗?
But the docker container still shuts down. Is there something I'm missing?
推荐答案
NGINX 1.19 在根目录下有一个文件夹 /docker-entrypoint.d
放置由docker-执行的启动脚本entrypoint.sh
脚本.您还可以阅读日志上的执行情况.
NGINX 1.19 has a folder /docker-entrypoint.d
on the root where place startup scripts executed by thedocker-entrypoint.sh
script. You can also read the execution on the log.
/docker-entrypoint.sh:/docker-entrypoint.d/不为空,会尝试执行配置
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh:在其中寻找 shell 脚本/docker-entrypoint.d/
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh:正在启动
/docker-entrypoint.sh: Launching
[........]
/docker-entrypoint.sh:配置完成;准备启动
/docker-entrypoint.sh: Configuration complete; ready for start up
这篇关于在 NGINX docker 容器中启动之前运行 bash 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 NGINX docker 容器中启动之前运行 bash 脚本


基础教程推荐
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01