portainer: Can't using vim editor on console connection with container.

Description

Can’t edit file in container through console terminal with vim command but everything is normal with nano tool.

Steps to reproduce the issue:

  1. run docker container to connect to swarm manager at swarm mode
  2. go to browser: http://my_swarm_ip:9000
  3. Sellect container and connect to console, install vim package, run command vi name_file.txt. Console will be freeze and log on console of google chrome:
 portainer.js:6 WebSocket connection to 'ws://10.1.3.4:9000/ws/exec?id=d2d8147c3b995c68d638802fddea63392b56979a69f1cf3ff5bad37f22db4b4d' failed: Could not decode a text frame as UTF-8

Technical details:

  • Portainer version: container have latest tag on docker hub
  • Target Docker version (the host/cluster you manage):
Client:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   b9f10c9
 Built:        Wed Jun  1 21:47:50 2016
 OS/Arch:      linux/amd64

Server:
 Version:      swarm/1.2.3
 API version:  1.22
 Go version:   go1.5.4
 Git commit:   eaa53c7
 Built:        Fri May 27 17:25:03 UTC 2016
 OS/Arch:      linux/amd64
  • Target Swarm version (if applicable):
docker swarm 1.12 with consul discovery service - Server Version: swarm/1.2.3
  • Platform (windows/linux): ubuntu 14.04x64
  • Browser: Google chrome: 53.0.2785.101 (Official Build) (64-bit)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 39 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s my solution for Dockerfile.

RUN apt-get update && apt-get install -y locales locales-all ENV LC_ALL en_US.UTF-8

@NextBlaubeere I’m supposing you’re using Portainer to access some container’s shell.

So, in the container you want vim to work, use those commands (inside Dockerfile) to set the encoding to UTF-8.

ENV LANG en_US.UTF-8  
ENV LC_ALL en_US.UTF-8
ENV LANGUAGE en_US.UTF-8  
RUN echo en_US UTF-8 >> /etc/locale.gen && locale-gen en_US.UTF-8 && DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales

P.S.: I’m assuming you’re using a Debian based image.

vim-tiny worked for me.

Not sure if this solves the problem for everyone, but this might have something to do with your locale settings. Simply set your locale in your Dockerfile or do something like this in your console:

echo "export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8">>~/.bash_profile
source .bash_profile

I don’t actually use portainer myself, but if the exception truly did originate from docker api websocket connection, then this should do the trick.

It works. I don’t understand why, but I’m happy it does! I did not have to change locale, installed vim package on ubuntu:18.04 and everything works as expected. (Also, I like the new Attach Console functionality) Thank you very much, @deviantony and @mrdrogdrog

After merging PR #2834 and #2842 this bug seems to be fixed.

on a Debian 9 and Ubuntu 18.04 base image, vim-tiny works. Full vim works if you set the locale to some variation of UTF-8. Running locale -a showed I already had C.UTF-8 installed so I set that by export LC_ALL=C.UTF-8 and full vim works. You should be able to set this persistently by setting LC_ALL in /etc/environment or in Dockerfile ENV.

Unfortunately, I do not know enough of websockets to know if Portainer can, or even should, fix anything here. But setting an appropriate locale on a host is always a good idea.

https://help.ubuntu.com/community/Locale

Update: After a little digging into websocket_exec.go, gorilla/websocket library and the websocket specs, I am certain this is a character encoding problem. WebSocket text messages are defined as always UTF-8. If the container returns invalid UTF-8 bytes it will fail to convert and I think this propagates up to kill the websocket connection.

To Summarize: WebSockets only use UTF-8, your container must use a UTF-8 locale to run a console reliably over a WebSocket connection.

Just in-case this helps anyone, I’m running into the same issue and was unable to get vi/vim working using any of the above suggestions.

However, I was able to install emacs and it works as expected.

after install sudo apt-get install language-pack-en-base locales vim can works for my all docker container @theAJFM ths. ths