cgrim
cgrim

Reputation: 5031

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.

Upvotes: 3

Views: 1815

Answers (1)

Charles Xu
Charles Xu

Reputation: 31414

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.

Upvotes: 2

Related Questions