When I start emacs -q and run M-x shell there is formatting error when connecting to docker container as follows,

$ docker container exec -it b3c85fd9c5eaa2e64fc5aac9025d1f9c3b3fe47ca39008f40ddd436338d755f5 bash
]0;root@b3c85fd9c5ea: /root@b3c85fd9c5ea:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
]0;root@b3c85fd9c5ea: /root@b3c85fd9c5ea:/# 

Here is its screenshot

enter image description here


2 Answers 2


Your value of PS1 contains ANSI escape codes that can only be processed correctly by a terminal emulator (like the built-in term.el or vterm), not by M-x shell or M-x eshell. Set it to something simpler like \u@\h:\w\$, this could be done with the -e switch for the docker-container-exec command.


Use cd instead of docker attach. So, at the eshell prompt, instead of attaching to a running container with

$ docker attach  <container_id>

cd into it with

$ cd /docker:<container_id>:/

You'll get the full eshell experience with this method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.