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?
I learned how to do it with the screen
multiplexer!
sudo screen -S azexec -dmL bash
azexec
-L
argument makes all output to be be saved into a file screenlog.0
-d
argument makes the terminal detachedsudo screen -S azexec -p 0 -X stuff "az container exec -g myresourcegroup -n nginxtest --exec-command /bin/bash^M"
az container exec
and after some time, the detached terminal switches to the container terminalsleep
for some time to let the az
command enter before running any othersudo screen -S azexec -p 0 -X stuff "ANY_COMMAND^M"
stuff
keyword^M
at the end of your commands, it simulates the enter keysleep
or handle completion of your commands some other way.screen
then you will not see the az
package installed in its terminal. But after you install it once in the screen terminal with apt
it stays there. It should be trivial to automate that process.az login
with --service-principal
if you want to automate this with Azure Pipelines