3

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.

cgrim
  • 4,890
  • 1
  • 23
  • 42
  • When you create a web app from a docker image, it's a web service, not a container. If you want to connect to it, you can install OpenSSH in the docker image. For this, you can try to follow this [link](https://learn.microsoft.com/en-us/azure/app-service/containers/tutorial-custom-docker-image). – Charles Xu Jul 27 '18 at 09:24
  • I would like to have a cleaner solution then pollute docker images with SSH server, have another process running there and have different versions of images for Azure. I hoped that there will be something like "az webapp container exec ...". – cgrim Jul 27 '18 at 16:50
  • If you just want to find a way to connect the web app or only need CLI command? – Charles Xu Jul 30 '18 at 06:01
  • I would like to have a CLI command but it seems that it does not exist :-( Sorry, but installing of SSH server into each Docker image is a bad practice and no way for me. – cgrim Aug 01 '18 at 12:50

1 Answers1

2

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.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • The container is still there running in the background of the web app and web app is in that case only as a proxy for that container. But I understand that `az container exec` should not work and I hoped that there is alternative for web app like 'az webapp container exec'. For example as it is analogously in Kubernetes with `kubectl exec` command where it proxies docker exec command to the target container running in the K8s pod. `az webapp remote-connection` also requires SSH server installed into Docker image :-( – cgrim Aug 01 '18 at 13:02
  • @cgrim It seems that what you said is not supported in Azure Web right. Maybe it will be supported in the future. If you want to connect to the web, as I know, there are just the two ways currently. – Charles Xu Aug 02 '18 at 00:51
  • @cgrim If the answer is helpful, you can accept it as an answer. – Charles Xu Aug 06 '18 at 08:35