bashubuntuazure-cliazure-container-instances

Automate az container exec


AZ CLI supports executing a single command in a running container.

az container exec -g myresourcegroup -n nginxtest --exec-command /bin/bash

Because of this, you cannot automate running multiple commands over existing container directly as you can with docker.

Is it possible to go around this with stdin, stdout, stderr redirection or multiplexing?


Solution

  • I learned how to do it with the screen multiplexer!

    Setup

    sudo screen -S azexec -dmL bash

    sudo screen -S azexec -p 0 -X stuff "az container exec -g myresourcegroup -n nginxtest --exec-command /bin/bash^M"

    Run any commands

    sudo screen -S azexec -p 0 -X stuff "ANY_COMMAND^M"

    Warning