Docker 在 Cloud Init Azure 上编写

Docker Compose on Cloud Init Azure

有一个 VM 规模集 运行 Centos 7 自定义映像。在缩放 VM 规模集时需要 运行 下面的脚本作为 cloud-init 脚本。但是 VM 缩放,脚本未执行。从服务器也无法找到执行历史记录。这是我使用的命令,

#cloud-config
runcmd:
– cd /srv/compose/composeforsvaret/
– docker-compose stop
- docker-compose up -d
final_message: "Your Docker server is now ready."

命令未执行,因为无法识别语法。
我在 cloud init documentation 中读到关于 runcmd

the list has to be proper yaml, so you have to quote any characters yaml would eat (':' can be problematic)

这应该可以解决问题:

runcmd:
– [ cd, /srv/compose/composeforsvaret, / ] // or - [ sh, -c , "cd /srv/compose/composeforsvaret" ]
– [ sh, -c, "docker-compose stop" ]
- [ sh, -c, "docker-compose up -d" ]
final_message: "Your Docker server is now ready."

另请记住,runcmd 仅在首次启动时运行,因此根据您的目的,您应该考虑 bootcmd!