0

I want to execute a number of commands with az container exec. The script was definitely working back in November 2020, but now a statement like

az container exec -n $containerGroupName -g $containerGroup.resourceGroup --exec-command "rm -rf /tmp/certificates/*"

returns this error:

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"
Kai Walter
  • 3,485
  • 2
  • 32
  • 62

1 Answers1

0

It seems there had been a change and az container exec only accepts executables.

So I had to turn the commands into a script 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/

add this script to Dockerfile

...
COPY challenge.sh /root/challenge.sh
RUN chmod u+x /root/challenge.sh

pass on all dynamic parameters as environment variables when creating the container group

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

and then only execute this script on the container instance:

az container exec -n $containerGroupName -g $containerGroup.resourceGroup --exec-command "/root/challenge.sh"
Kai Walter
  • 3,485
  • 2
  • 32
  • 62