[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using docker-tramp with sudo

From: Tim Landscheidt
Subject: Using docker-tramp with sudo
Date: Wed, 20 Sep 2017 14:37:48 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)


I want to and use docker-tramp
( to access
Docker containers with Emacs 25.3.1.  By default, this uses
the "docker" binary:

| […]

| (defcustom docker-tramp-docker-executable "docker"
|   "Path to docker executable."
|   :type 'string
|   :group 'docker-tramp)

| […]

| ;;;###autoload
| (defun docker-tramp-add-method ()
|   "Add docker tramp method."
|   (add-to-list 'tramp-methods
|                `(,docker-tramp-method
|                  (tramp-login-program      ,docker-tramp-docker-executable)
|                  (tramp-login-args         (,docker-tramp-docker-options 
("exec" "-it") ("-u" "%u") ("%h") ("sh")))
|                  (tramp-remote-shell       "/bin/sh")
|                  (tramp-remote-shell-args  ("-i" "-c")))))

| ;;;###autoload
| (eval-after-load 'tramp
|   '(progn
|      (docker-tramp-add-method)
|      (tramp-set-completion-function docker-tramp-method 

| […]

On Fedora, "docker" must be called as root, e. g. "sudo
docker".  When I customize-variable'd
docker-tramp-docker-executable for the first time, it did
not update tramp-methods automatically, i. e. either I had
to restart Emacs or manually amend tramp-methods:

| (setcdr (assoc 'tramp-login-program
|                (cdr (assoc "docker" tramp-methods)))
|         "sudo docker")

AFAICT, TRAMP treats the data in tramp-methods as strings
only, i. e. there is no possibility for dynamic evaluation.
Is that correct?  (If I'm not mistaken, one could partially
work around that by adding ":set" functions to the defcustom
definitions of docker-tramp-docker-executable and
docker-tramp-docker-options that would amend tramp-methods,
but that would not work for setting those variables with
setq & Co.)

Second, customizing docker-tramp-docker-executable to "sudo
docker" is not really the best solution anyhow, as for the
list of running containers, docker-tramp does:

| (defun docker-tramp--running-containers ()
|   "Collect docker running containers.

| Return a list of containers of the form: \(ID NAME\)"
|   (cl-loop for line in (cdr (ignore-errors (apply #'process-lines 
docker-tramp-docker-executable (append docker-tramp-docker-options (list 
|            for info = (split-string line "[[:space:]]+" t)
|            collect (cons (car info) (last info))))

process-lines expects its argument PROGRAM to be, well, a
program, not a shell command, thus this will never work when
docker-tramp-docker-executable is "sudo docker".

More importantly, this scenario feels very much like it
would be a use case for TRAMP's multi-hop model: First you
hop to "sudo", then to "docker".  But I'm at a loss for what
to put in tramp-default-proxies-alist.  When I try:

| C-x C-f /sudo:address@hidden|docker:address@hidden:/ RET

TRAMP fails with:

| tramp-file-name-handler: Wrong type argument: listp, "docker"

and adds:

| ("ae1f80d59e71081c7b2f3e3671b2a31a43c8344cda54e5272674ccfe331d9f5b" "root" 

to tramp-default-proxies-alist.

Am I missing something obvious or is this hopping not possi-


reply via email to

[Prev in Thread] Current Thread [Next in Thread]