给出以下撰写文件:
version: '3.6'
services:
hello-world:
image: hello-world
environment:
- test:test
如果我使用
docker stack deploy -c docker-compose.yml test
部署它,则按如下方式修改撰写文件:
services:
hello-world:
image: hello-world
environment:
- test:test
- test2:test2
现在,如果我运行
docker service inspect test_hello-world
,我会在任务模板中看到以下内容:
"Env": [
"test:test"
],
是否有一个命令可以用来获取从撰写文件添加的第二个环境变量(test2)?
请在运行
docker ps -a
后运行docker stack deploy -c docker-compose.yml test
。可以看到容器的状态是Exited (0)
。这意味着你的容器当时没有运行。
使用
test2:test2
更新 docker-compose.yml 并运行 docker service inspect test_hello-world
后,您不会更新您的服务,因为它之前已退出(终止)。
请在使用
docker stack deploy -c docker-compose.yml test
更新 docker-compose.yml
后再次运行 test2:test2
。然后就可以看到已经更新并再次退出了。我测试了它以确保它能像那样工作。
输出:
"Env": [
"test2:test2",
"test:test"
],