在 NGINX docker 容器中启动之前运行 bash 脚本

Running a bash script before startup in an NGINX docker container(在 NGINX docker 容器中启动之前运行 bash 脚本)
本文介绍了在 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 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)