2

I am trying to use Tramp to log into a Docker container running on a VM.

My Docker-related setup looks like this:

(add-to-list 'tramp-methods
             '("docker-exec"
               (tramp-login-program "docker")
               (tramp-login-args
                (("exec" "-ti") ("%h") ("/bin/sh")))
               (tramp-remote-shell "/bin/sh")
               (tramp-remote-shell-args ("-i") ("-c"))))

I can use this on my machine to access directories inside container, but when I try to "hop" to remote machine like this: C-x C-f/ssh:root@vm|docker-exec:ed703f92ae19:/ Tramp will at first get confused about ls command because it would add a ^M characters at the end of the line and thus tramp-find-executable will return something like /usr/bin/ls^M, which would generate invalid command.

I was able to overcome this with:

(defun my/tramp-find-executable
    (func vec progname dirlist &optional ignore-tilde ignore-path)
  (org-trim (funcall func vec progname dirlist ignore-tilde ignore-path)))

(advice-add 'tramp-find-executable
            :around 'my/tramp-find-executable)

But now I get this error:

byte-code: Wrong type argument: number-or-marker-p, //DIRED-OPTIONS//

And the log looks like this:

//DIRED-OPTIONS// --quoting-style=literal
///c92423c4fd16f4857a1b9d765f804f3e#$
17:32:16.175776 tramp-get-connection-property (7) # check-remote-echo nil
17:32:16.175817 tramp-get-connection-property (7) # check-remote-echo nil
17:32:16.175869 tramp-wait-for-regexp (6) # 
  total 292
  drwxr-xr-x  18 root root   4096 Feb 24 09:08 .
  drwxr-xr-x  18 root root   4096 Feb 24 09:08 ..
  -rwxr-xr-x   1 root root      0 Feb 24 09:08 .dockerenv
  -rwxr-xr-x   1 root root      0 Feb 24 09:08 .dockerinit
  lrwxrwxrwx   1 root root      7 Mar 30  2015 bin -> usr/bin
<<< skipped >>>
  drwxrwxrwt   2 root root   4096 Feb 24 15:29 tmp
  drwxr-xr-x  13 root root   4096 Mar 30  2015 usr
  drwxr-xr-x  18 root root   4096 Mar 30  2015 var
//DIRED// 59 60 108 110 158 168 216 227 275 278 337 340 388 391 439 443 491 494 553 558 619 629 677 682 730 733 781 784 832 836 884 888 936 939 987 991 1051 1058 1106 1109 1157 1160 1208 1217 1265 1268 1316 1319 1367 1370
//DIRED-OPTIONS// --quoting-style=literal
///c92423c4fd16f4857a1b9d765f804f3e#$

I don't know what Tramp was trying to do, when it received this error, so I cannot think of a way to fix it. But, maybe this is a known bug? Or, maybe I need some extra settings for Tramp so that it would not add ^Ms? (I doubt they are in the original output since both machines run Linux, both CentOS.

  • It isn't Tramp that's adding those CR, but they may be added due to something in the Tramp, SSH or Docker configuration. Do you have any options set in your .ssh/config, and if so can you reproduce this without them? In particular RequestTTY would cause this. – Gilles 'SO- stop being evil' Feb 24 '16 at 17:15
  • @Gilles nope, I don't even have a .ssh/config file. Docker configuration may sound more promising, but I wouldn't know where to look at. Besides, Tramp is able to do either one of the hops separately, it's only when they are piped the problem occurs. – wvxvw Feb 25 '16 at 8:13
  • I'm not familiar with docker, but why do you pass it the -t option? That causes it to allocate a terminal, which shouldn't be necessary for Tramp. And the fact that there's a terminal is what causes the CR to be present. I don't know if Tramp has some mechanism that suppresses CR sometimes, but if they aren't there in the first place, the issue is moot. – Gilles 'SO- stop being evil' Feb 25 '16 at 8:26
  • I've never tried it myself, but in ELPA there's a package docker-tramp. Maybe you give it a try, instead defining your own? And in case something must be improved, it would be better to do it there, other people would profit from this. – Michael Albinus Feb 25 '16 at 9:07
  • @Gilles if I remove the -t bit, Tramp hangs for a while and then gives up. I can still see the ^Ms though. The last line it prints (few dozens times) is exec docker exec -i 74b79b8b67a2 /bin/sh^M, and then it prints a huge backtrace, where the last call seems to be tramp-maybe-open-connection(["docker-exec" nil "74b79b8b67a2" "/" "ssh:root@vm|"]) – wvxvw Feb 25 '16 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.