gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 04:29:40 24 4
gpt4 key购买 nike

我正在尝试使用 docker 在 localhost:8000 上运行一个 javascript 应用程序。我想做的部分工作是根据 docker run 命令换出一些配置文件,我想将一个环境变量传递到容器中,以便 bash 脚本可以将其用作参数。

我的 dockerfile 是这样的:

FROM nginx
COPY . /usr/share/nginx/html
CMD ["bash","/usr/share/nginx/html/runfile.sh"]

bash 脚本如下所示:

#!/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。

但是,如果我将 dockerfile 更改为使用 ENTRYPOINT 而不是 CMD,则 -e 标志有效但网络服务器不会启动。

我在这里缺少什么吗? ENTRYPOINT 是否被重写了?

编辑:

所以我更新了我的 dockerfile 以使用 ENTRYPOINT ["bash","/usr/share/nginx/html/runfile.sh", ";", "nginx -g daemon off;"]

但是 docker 容器仍然关闭。有什么我想念的吗?

最佳答案

NGINX 1.19 在根目录下有一个文件夹 /docker-entrypoint.d,其中放置由 docker-entrypoint.sh 脚本执行的启动脚本。您还可以在日志中阅读执行情况。

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, willattempt to perform configuration

/docker-entrypoint.sh: Looking for shell scripts in/docker-entrypoint.d/

/docker-entrypoint.sh: Launching

[..........]

/docker-entrypoint.sh: Configuration complete; ready for start up

关于javascript - 在 NGINX docker 容器中启动前运行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40608055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com