我正在try 使用一个定制配置文件(让我们称之为custom.configuration.conf
)在Docker中运行一个定制-nginx服务器
并且,我希望容器根据部署环境 Select 配置文件.因此,在我的存储库中,我将配置如下:
configuration(folder)
|
----> qa (sub-folder of configuration folder)
|
----> custom.configuration.conf
|
----> prd (sub-folder of configuration folder)
|
---> custom.configuration.conf
为了动态地 Select 这些文件,我引入了一个环境变量DEPLOYMENT_ENVIRONMENT
,我在一个名为start.sh
的文件中使用它
start.sh
脚本如下:
cp configuration/${DEPLOYMENT_ENVIRONMENT}/custom.configuration.conf /etc/nginx/conf.d
nginx -g "daemon off;"
我的文档文件如下所示:
FROM nginx:1.23-alpine as application
WORKDIR /build
COPY configuration configuration
COPY start.sh start.sh
ENTRYPOINT /build/start.sh
我用来构建和运行容器的命令是:
docker build -t custom-nginx .
docker run -e DEPLOYMENT_ENVIRONMENT=qa -p 8080:80 custom-nginx
然而,当我docker exec
进入容器时,我看不到/etc/nginx/conf.d
的custom.configuration.conf
.
我在一台装有Docker Desktop的Windows 10计算机上运行这个程序.
start.sh
、Dockerfile
和configuration
文件夹/文件位于我的存储库中的根级别.
我不知道我做错了什么.请帮助我理解为什么我不能将文件从一个容器复制到另一个容器.
附言:我实际上try 在容器内运行cp configuration/${DEPLOYMENT_ENVIRONMENT}/custom.configuration.conf /etc/nginx/conf.d
命令,以判断该命令是否错误.然而,如果我在容器中手动执行它,它可以工作,但当我使用docker run
运行它时,它失败了.