Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

az container exec when using Docker compose

Is it possible to execute command in a container which is running under Azure WebApp service by Docker Compose?

When I create single container by az container create ..., then it works. But when I create set of containers by Docker compose script using az webapp create --multicontainer-config-type compose ..., then it does not work.

From logs I see that there is running container myWebApp_myContainer_1 so I try:

az container exec -g myResourceGroup -n myWebApp_myContainer_1 --exec-command "/bin/bash"

With this result:

The Resource 'Microsoft.ContainerInstance/containerGroups/myWebApp_myContainer_1' under resource group 'myResourceGroup' was not found.

Then I try:

az container exec -g myResourceGroup -n myWebApp --container-name myWebApp_myContainer_1 --exec-command "/bin/bash"

With this result:

The Resource 'Microsoft.ContainerInstance/containerGroups/myWebApp' under resource group 'myResourceGroup' was not found.

Note that it is normally possible to execute commands in containers started by Docker compose script on local Docker (out of Azure).

Update I don't like to install SSH server into Docker images. It is a bad approach. I'm looking for a way of direct exec like az container exec does.

Thank you for any hint.

like image 776
cgrim Avatar asked Aug 23 '26 18:08

cgrim


1 Answers

For your issue, when the web app created from a Docker image, it's just a web app, not a container. So you cannot use the command az container exec to connect to it.

If you really want to connect to the web app that created from a Docker image, there are two ways as I know to achieve it.

The one is that I describe in the comment, you should install the OpenSSH server in the Docker image. Then ssh into the web app from the port exposed to the Internet.

The other one as you wish is using the command az webapp remote-connection. For more details, you can read Open SSH session from remote shell.

like image 124
Charles Xu Avatar answered Aug 25 '26 19:08

Charles Xu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!