我们在工作时构建了一个容器'pepsr‘,它使用了一个通用配置文件'install.config.json’。这个配置文件包含所有必要的信息,这些信息使pepsr能够知道运行它的主机的具体情况。
我想要做一个合成yml,它只需要使用pepsr图像并将'harvard.installation.config.json‘复制为'installation.config.json’,以便最终容器知道它在‘哈佛’上运行。
我梦见的生成生成器脚本如下所示:
$ ./makeRelease harvard调用docker-compose build。
因此,脚本应该生成名为'pepsr-hardvard‘的图像。
换句话说,makeRelease.sh脚本应该使docker-compose执行以下操作:
'pepsr';
COPY <nameOfTheInstallation>.installation.config.json installation.config.json
nameOfTheInstallation;pepsr-<nameOfTheInstallation>重要事项:我们放弃了--卷选项来引用配置文件,因为我们想要一个全部为一体的结果容器:
run;
欢迎任何其他选择:)
发布于 2021-09-13 08:55:15
“码头工”并不能满足你的要求。为此您需要一个Dockerfile。
FROM pepsr
ARG RELEASE_NAME
COPY ${RELEASE_NAME}.installation.config.json installation.config.json然后你就可以把它用在你的船坞里了。
version: "3.9"
services:
pepsr-release:
image: "myregistry.io/pepsr-${RELEASE_NAME}:${RELEASE_TAG}"
build:
context: ./
args:
RELEASE_NAME:如果.env file存在于您的目录中,Docker将读取它,并使用您当前在shell中设置的任何变量(如果设置了这两个变量,则优先使用shell)。如果使用空值的build arg这样的变量,compose将使用它找到的env变量的值。
因此,您可以在撰写文件旁边创建这样一个.env file,其中包含RELEASE_NAME,或者在shell中设置它,如下所示。
export RELEASE_NAME="harvard"
export RELEASE_TAG="0.0.1"
docker-compose build
docker-compose push您甚至可以使用env变量来命名图像或标记图像,如上面所示。
对于这个例子,需要一个docker-compose.yaml和一个Dockerfile相邻。
.
|-- docker-compose.yaml
|-- Dockerfile发布于 2021-09-13 08:13:09
为每个主机构建一个映像似乎有点不像Docker,因为Docker的优点之一是您的映像可以在任何地方运行,没有变化。
如果您不想使用卷或绑定挂载,那么我唯一能想到的就是将文件管道到容器中。就像这样
$ cat harvard.installation.config.json | docker run --rm -i <myimage>然后,您就可以在映像中从stdin读取配置文件。
发布于 2021-09-14 16:01:03
我终于想出了以下解决方案:我编写了两个docker文件:
Dockerfile.pepsr.generic;用于Pepsr安装的CMD npm start来启动perpsr通用nodeJs应用程序.的Dockerfile.pepsr.installation
我的撰写文件docker-compose.yml如下:
version: "3.9"
services:
pepsr-generic:
build:
dockerfile: Dockerfile.pepsr.generic
context: .
image: <myrepo>/pepsr-generic
container_name: pepsr-generic
network_mode: host
restart: always
pepsr-install:
build:
dockerfile: Dockerfile.pepsr.installation.release
context: .
args:
INSTALLATION_NAME:
hostname: pepsr-${INSTALLATION_NAME}
network_mode: host
image: <myrepo>/pepsr-${INSTALLATION_NAME}
container_name: pepsr-${INSTALLATION_NAME}
restart: unless-stopped
depends_on:
- pepsr-generic基本上,我的作文说:
最后,为了简化构建,我提供了一个bash脚本,它将INSTALLATION_NAME环境变量传递给docker,如下所示(流线型版本):
#!/bin/bash
module=" dockerPepsrMakeRelease"
TODAY=$(TZ=":GMT" date '+%Y-%m-%dT%H:%M:%S')
echo " ____"
echo " | _ \ ___ _ __ ___ _ __ "
echo " | |_) / _ \ '_ \/ __| '__|"
echo " | __/ __/ |_) \__ \ | "
echo " |_| \___| .__/|___/_| "
echo " |_| "
echo "---------------------------"
echo PEPSR: Release manager for Docker
export INSTALL_NAME=$1
docker-compose build
retVal=$?
if [ $retVal -ne 0 ]; then
echo " $module: error: could not docker-compose build. Aborted"
exit 1
fi
echo " $module: image completed."
exit 0https://stackoverflow.com/questions/69159170
复制相似问题