azure-cli: 'az container exec' does NOT run /bin/bash
az feedback
auto-generates most of the information requested below, as of CLI version 2.0.62
Describe the bug
I’ve created the Docker image and I can launch container from it using ‘docker’ tool: docker build --compress --tag $image_id:$tag_id --file Dockerfile-$image_id .
I can successfully run /bin/bash inside a container: ‘docker exec --interactive --tty PostgresProStandard12 bash’
I’ve put the image into ACR and I can launch container from it using ‘az’ tool:
az container create
–resource-group dockers
–name debiandocker
–image $loginServer_id/$image_id:$tag_id
–cpu 2
–memory 2
–registry-login-server $loginServer_id
–registry-username pgprostdacr
–registry-password $password_id
–dns-name-label $image_id
–ports 5433
–no-wait
I used to run /bin/bash inside a container some time ago
az container exec
–resource-group dockers
–name debiandocker
–exec-command “/bin/bash”
–container-name debiandocker
but I cannot do it now - when I run previous command, nothing happens - I simply stay in my OS CLI environment
I can verify the container is up & running by:
az container list
–resource-group dockers
az container show
–resource-group dockers
–name debiandocker
az container logs
–resource-group dockers
–name debiandocker
–container-name debiandocker
az container attach
–resource-group dockers
–name debiandocker
–container-name debiandocker
It looks to me something has been broken with ‘az’ tool, since it all worked before and have not changed anything in my Dockerfile.
To Reproduce
Create container and try to run /bin/bash inside of it
Expected behavior
By running
az container exec
–resource-group dockers
–name debiandocker
–exec-command “/bin/bash”
–container-name debiandocker
I expect, like before, to get inside of container
Environment summary
root@ubuntu16:~# az --version azure-cli 2.14.2
core 2.14.2 telemetry 1.0.6
Python location ‘/opt/az/bin/python3’ Extensions directory ‘/root/.azure/cliextensions’
Python (Linux) 3.6.10 (default, Nov 9 2020, 06:00:25) [GCC 5.4.0 20160609]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
Additional context
It used to work without any issues, probably several months ago, but does not work any longer. Since I have not changed anything with my Dockerfile and it still works with ‘docker’ tool, I suspect something wrong with ‘az’ tool.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 33 (7 by maintainers)
Commits related to this issue
- {container} Bugfix #15856: az container exec - remove eol check to avoid closing terminal before it even started on linux The backend sends an empty webSocket message after establishing an connection... — committed to Azure/azure-cli by bitcloud 3 years ago
- {container} Bugfix #15856,#18251,#18275: az container exec - decode received bytes as utf-8 string (#18384) * decode binary string as utf-8 * updates suggested code style changes — committed to Azure/azure-cli by bitcloud 3 years ago
- {container} Bugfix #15856,#18251,#18275: az container exec - decode received bytes as utf-8 string (#18384) * decode binary string as utf-8 * updates suggested code style changes — committed to viparek/azure-cli by bitcloud 3 years ago
- Merge remote-tracking branch 'azure/dev' into Aladdin-src (#19131) * {Doc} Add managed identity command guideline (#17473) * [WebApp] Add to `az webapp deploy` param help text (#17743) * Add to... — committed to Azure/azure-cli by kairu-ms 3 years ago
The issue got introduced by the backend.
The problem lies here: https://github.com/Azure/azure-cli/blob/879396f3c9ec4dd090b595eeabb36b8dde2007ec/src/azure-cli/azure/cli/command_modules/container/custom.py#L684
This function loops over the websocket output and if the socket emits an empty string it is considered end of session. But currently the backend seems to start with an empty string before emitting the real output.
by just commenting out this and the next line, it works again, but the eol detection is gone then. which is kind of okay, because if the terminal ends, the socket closes anyway from the server side.
I don’t know as I don’t work for MS 😉 But if you need it right away, you can easily patch you local version.
On the mac the file is located
/usr/local/Cellar/azure-cli/2.14.1/libexec/lib/python3.8/site-packages/azure/cli/command_modules/container/custom.py
check for the function
_cycle_exec_pipe
and just remove the two lines 4 and 5 in the function (if not data: return False
)This should get you working until they release a new version.
P.S.: This is on my mac on an homebrew installed version of the azure-cli. The path can differ based on your version and installation method.
@alexeyshishkin01 it has landed in the 2.18.0 version. (see https://github.com/MicrosoftDocs/azure-docs-cli/blob/master/docs-ref-conceptual/release-notes-azure-cli.md#container) please try that one.