Azure 容器实例命令执行 returns "no such file or directory"
Azure Container Instance command execution returns "no such file or directory"
我想用 az container exec
执行一些命令。 script 肯定在 2020 年 11 月就开始工作了,但现在像
这样的声明
az container exec -n $containerGroupName -g $containerGroup.resourceGroup --exec-command "rm -rf /tmp/certificates/*"
returns 这个错误:
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"rm -rf /tmp/certificates/*\": stat rm -rf /tmp/certificates/*: no such file or directory"
似乎发生了变化,az container exec
只接受可执行文件。
所以我不得不把命令变成脚本challenge.sh
#!/bin/sh
rm -rf /tmp/certificates/*
certbot register --email $EMAIL --server $SERVERURL --eab-kid $EABKID --eab-hmac-key $EABHMACKEY --agree-tos -n
certbot certonly --nginx --email $EMAIL --server $SERVERURL -d $DOMAIN
cp -avr /etc/letsencrypt /tmp/certificates
cp /var/log/letsencrypt/letsencrypt.log /tmp/certificates/
将此脚本添加到 Dockerfile
...
COPY challenge.sh /root/challenge.sh
RUN chmod u+x /root/challenge.sh
创建容器组时将所有动态参数作为环境变量传递
az container create --name $containerGroupName -g $registry.resourceGroup `
--image $image `
--registry-login-server $registry.loginServer --registry-username $credentials.username --registry-password $credentials.passwords[0].value `
--ip-address public `
--azure-file-volume-account-name $storageAccountName `
--azure-file-volume-account-key $storageAccountKey `
--azure-file-volume-share-name $storageAccountShareName `
--azure-file-volume-mount-path "/tmp/certificates" `
--environment-variables DOMAIN=esb-dev.$dnsSuffix `
--secure-environment-variables EMAIL=$EmailAddress SERVERURL=$ServerUrl EABKID=$EABKID EABHMACKEY=$EABHMACKEY
然后仅在容器实例上执行此脚本:
az container exec -n $containerGroupName -g $containerGroup.resourceGroup --exec-command "/root/challenge.sh"
我想用 az container exec
执行一些命令。 script 肯定在 2020 年 11 月就开始工作了,但现在像
az container exec -n $containerGroupName -g $containerGroup.resourceGroup --exec-command "rm -rf /tmp/certificates/*"
returns 这个错误:
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"rm -rf /tmp/certificates/*\": stat rm -rf /tmp/certificates/*: no such file or directory"
似乎发生了变化,az container exec
只接受可执行文件。
所以我不得不把命令变成脚本challenge.sh
#!/bin/sh
rm -rf /tmp/certificates/*
certbot register --email $EMAIL --server $SERVERURL --eab-kid $EABKID --eab-hmac-key $EABHMACKEY --agree-tos -n
certbot certonly --nginx --email $EMAIL --server $SERVERURL -d $DOMAIN
cp -avr /etc/letsencrypt /tmp/certificates
cp /var/log/letsencrypt/letsencrypt.log /tmp/certificates/
将此脚本添加到 Dockerfile
...
COPY challenge.sh /root/challenge.sh
RUN chmod u+x /root/challenge.sh
创建容器组时将所有动态参数作为环境变量传递
az container create --name $containerGroupName -g $registry.resourceGroup `
--image $image `
--registry-login-server $registry.loginServer --registry-username $credentials.username --registry-password $credentials.passwords[0].value `
--ip-address public `
--azure-file-volume-account-name $storageAccountName `
--azure-file-volume-account-key $storageAccountKey `
--azure-file-volume-share-name $storageAccountShareName `
--azure-file-volume-mount-path "/tmp/certificates" `
--environment-variables DOMAIN=esb-dev.$dnsSuffix `
--secure-environment-variables EMAIL=$EmailAddress SERVERURL=$ServerUrl EABKID=$EABKID EABHMACKEY=$EABHMACKEY
然后仅在容器实例上执行此脚本:
az container exec -n $containerGroupName -g $containerGroup.resourceGroup --exec-command "/root/challenge.sh"