Azure / azure-cli

Azure Command-Line Interface

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

az container exec: garbage characters inserted at shell prompt

mmacy opened this issue · comments

Describe the bug
When exec'ing a shell in an Alpine-based container running in Azure Container Instances, garbage characters are inserted on key press. In the example output below, the ls command is attempted, but [6;5R was inserted when the "l" key was pressed, and the command fails:

$ az container exec -g rg604 -n alpine-test-02 --exec-command "/bin/ash"
/ # [6;5Rls
/bin/ash: [6: not found
/bin/ash: 5Rls: not found
/ # 

To Reproduce

  1. Start Alpine container in ACI:

    $ az container create -g rg604 -n alpine-test-02 --image alpine --command-line "tail -f /dev/null"
  2. Use az container exec to spawn and attach to the ash shell in the container:

    $ az container exec -g rg604 -n alpine-test-02 --exec-command "/bin/ash"
  3. Once inside the container, execute the ls command to list directory contents:

    $ az container exec -g rg604 -n alpine-test-02 --exec-command "/bin/ash"
    / # [6;5Rls
    /bin/ash: [6: not found
    /bin/ash: 5Rls: not found
    / # 

    Note the characters [6;5R were inserted when the "l" key was pressed, causing the ls command to fail.

This above example output was from Bash on Ubuntu 18.04, but this behavior also occurs in the Cloud Shell:

marsh@Azure:~$ az container exec -g rg604 -n alpine-test-02 --exec-command "/bin/ash"
/ # [10;5Rls
/bin/ash: [10: not found
/bin/ash: 5Rls: not found
/ #

Expected behavior
When exec'ed into a container instance, I should be able to enter commands in the terminal without "garbage" characters being inserted on keypress.

Environment summary

  • Install Method : apt on Ubuntu, and the included az on Cloud Shell
  • CLI version: 2.0.34
  • OS: Ubuntu 18.04 and Cloud Shell
  • Shell: bash on Ubuntu and Cloud Shell

Additional context
Exec'ing into a locally run Alpine container does not exhibit this behavior:

$ docker run -d alpine tail -f /dev/null
d375353c5f36d6d1bb799df9d9708d9c2e5ec1bfb39080085948d12c052f3665
$ docker exec -it d375353c5f36 /bin/ash
/ # ls
bin    etc    lib    mnt    root   sbin   sys    usr
dev    home   media  proc   run    srv    tmp    var
/ # 

@tjprescott I don't see this behavior reproduce when we exec into a container with anything besides Azure CLI - it seems like this may be behavior from python/cli? Can you take a look at this or is there any known python output issues?

I'm facing the exact same issue with an alpine based container:

`bash

az container exec --name frontend --exec-command /bin/sh
/app # [33;8Rls
/bin/sh: [33: not found
`

Mee too, tried from linux and windows 10
But fun fact: in linux, you can delete them by backspace :) Just need to start every command by some backspace.

Pressing backspace also creates some garbage:

[73;29

If you use bash in an alpine based container instead of /bin/sh, then there is no garbage :) (from linux)

I am facing the same issue - a lot of garbase, hard to read the terminal

try to perform that command after login

env TERM=vt1000 /bin/bash

@KEMBL Thanks for the tip, however, the Alpine image in its default configuration does not include the Bash shell. The ash and sh shells within the image are provided by busybox, so the cause is likely within how the terminal is handled there.

I'm experiencing the same issue on an image based on Ubuntu 18.04, specifically mcr.microsoft.com/powershell. The issue occurs for /bin/bash, /bin/sh and /usr/bin/pwsh.

Using the suggested env TERM=vt1000 /bin/bash worked for /bin/bash, but the issue reappeared if I then launched pwsh from it.

I'm experiencing the same issue.

My host is Windows 10:1903 and I'm connecting to a running container built from the mcr.microsoft.com/windows:1809 image.

The console is filled with garbage, command output is almost unreadable.

Update. I've noticed that the Cmder displays output without a garbage. Using it as a workaround.

@dkkapur can you please take ownership of this issue?

Im having the same issues when launching from ubuntu. How come this is taking YEARS to fix?

@dkkapur please look into this!

If you provide a .vimrc containing set nocompatible and use the azure container webgui Connect you can get in there to edit a file. Otherwise the "az container exec" is useless... Why has this taken YEARS to fix. @dkkapur

I'm facing the same error. Is there a fix now?

I connect to the container using
az container exec --name [name] --resource-group [rg_name] --exec-command "/bin/sh"
Every time I press ENTER I've these input in the new line
~ # [54;5R

I just reported this to my azure support account. Ticket number 119091824005018.

Same is happening to me, container is openjdk:8-jre-alpine3.9 and I get plenty of:

/ # [55;5Rls
sh: [55: not found
sh: 5Rls: not found

Thanks!

Same here as above on windows and osx. The entire experience with az container exec is riddled with bugs and old unresolved issues, please fix!

Same problem.
If it contributes to troubleshooting, that seems to be cursor position report sent as ANSI Terminal Control Escape sequence, per docs (googled from multiple places):

Report Cursor Position <ESC>[{ROW};{COLUMN}R

However, I'm not sure how to switch cursor position reporting off yet, is it Azure issue or alpine issue.

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @dkkapur.

container