mer*_*hoo 9 docker docker-compose
我有一个 docker compose 文件,其中包含 2 个专有配置文件local
和dev
,我们使用它进行本地测试并拉下开发环境进行调试。
有没有一种方法可以默认为,local
以便我们可以docker-compose build
在不指定的情况下使用--profile
,并且 docker 将默认为local
?
您需要使用COMPOSE_PROFILES环境变量。要始终设置它,您可以输入:
COMPOSE_PROFILES=local
在/etc/环境中
或者...
export COMPOSE_PROFILES=local
在~/.bashrc或~/.zshrc中
然后重新启动你的外壳。您可以输入以下内容以确保您的 shell 已获取环境变量:
echo $COMPOSE_PROFILES
我只是在玩这个;事实证明,使用空字符串作为配置文件的服务将在未指定配置文件时启动,但与没有指定配置文件的服务不同,在指定另一个配置文件时不会启动。
\n虽然应该指出的是,这没有记录在案,因此功能将来可能会发生变化,但我认为在变量不足的情况下实现一个不错的“默认”配置文件功能应该足够了COMPOSE_PROFILES
。
例如
\nservices:\n a:\n image: busybox\n profiles:\n - \'\'\n b:\n image: busybox\n profiles:\n - \'\'\n - a\n c:\n image: busybox\n profiles:\n - a\n
Run Code Online (Sandbox Code Playgroud)\naj@laptop:~/test$ docker compose up\n[+] Running 2/0\n \xe2\x9c\x94 Container test-b-1 Created 0.0s \n \xe2\x9c\x94 Container test-a-1 Created 0.0s \nAttaching to test-a-1, test-b-1\ntest-a-1 exited with code 0\ntest-b-1 exited with code 0\n\naj@laptop:~/test$ docker compose --profile a up\n[+] Running 2/0\n \xe2\x9c\x94 Container test-c-1 Created 0.0s \n \xe2\x9c\x94 Container test-b-1 Created 0.0s \nAttaching to test-b-1, test-c-1\ntest-b-1 exited with code 0\ntest-c-1 exited with code 0\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
3835 次 |
最近记录: |