mviereck / x11docker

Run GUI applications and desktops in docker and podman containers. Focus on security.
MIT License
5.62k stars 378 forks source link

Quoted image command arguments are not parsed accordingly #112

Closed eine closed 5 years ago

eine commented 5 years ago

I am trying to execute winpty docker run --rm -it x11docker/xfce bash -c "ls && pwd" with x11docker.

...
x11docker WARNING: Option --clipboard is not supported for --tty.
  Fallback: Disabling option --clipboard.

x11docker note: Did not find container init system 'tini'.
  This is a bug in your distributions docker package.
  Normally, docker provides init system tini as '/usr/bin/docker-init'.

  x11docker uses tini for clean process handling and fast container shutdown.
  To provide tini yourself, please download tini-static:
    https://github.com/krallin/tini/releases/download/v0.18.0/tini-static
  Store it in one of:
    /home/eine/.local/share/x11docker/
    /usr/local/share/x11docker/

/fakehome/eine
/usr/bin/ls: /usr/bin/ls: cannot execute binary file
...
x11docker note: Did not find container init system 'tini'.
  This is a bug in your distributions docker package.
  Normally, docker provides init system tini as '/usr/bin/docker-init'.

  x11docker uses tini for clean process handling and fast container shutdown.
  To provide tini yourself, please download tini-static:
    https://github.com/krallin/tini/releases/download/v0.18.0/tini-static
  Store it in one of:
    /home/eine/.local/share/x11docker/
    /usr/local/share/x11docker/

eine@2aa7533005d5:~$ exit
exit

NOTE: with ./x11docker -i -t x11docker/xfce "ls -la && bash" the output is:

eine@0bc040f292cf:~$ exit
exit
total 24
drwxr-xr-x 2 eine None 4096 Jan 29 22:42 .
drwxrwxrwx 3 root root 4096 Jan 29 22:42 ..
-rw------- 1 eine None    5 Jan 29 22:42 .bash_history
-rw-r--r-- 1 eine None  220 Jan 29 22:42 .bash_logout
-rw-r--r-- 1 eine None 3526 Jan 29 22:42 .bashrc
-rw-r--r-- 1 eine None  807 Jan 29 22:42 .profile

NOTE: ./x11docker -i -t x11docker/xfce "pwd && bash" shows the output of pwd.

However, in neither case is a command prompt provided after. The container exists instead. This is different from the results reported in #110.

...
x11docker WARNING: Option --clipboard is not supported for --tty.
  Fallback: Disabling option --clipboard.

x11docker note: Did not find container init system 'tini'.
  This is a bug in your distributions docker package.
  Normally, docker provides init system tini as '/usr/bin/docker-init'.

  x11docker uses tini for clean process handling and fast container shutdown.
  To provide tini yourself, please download tini-static:
    https://github.com/krallin/tini/releases/download/v0.18.0/tini-static
  Store it in one of:
    /home/eine/.local/share/x11docker/
    /usr/local/share/x11docker/

eine@e489ccf9645b:~$ exit
exit
/usr/bin/ls: /usr/bin/ls: cannot execute binary file
mviereck commented 5 years ago

Two bugs come together here, one in x11docker and one in x11docker/xfce image.

https://github.com/mviereck/x11docker/commit/8d30aa4d94ed2a2694d083dc8ef4a875326b4bd8 fixes the bug in x11docker. The quotes around "ls && pwd" are now preserved accurately. The fix also preserves quotes in DOCKER_RUN_OPTIONS. The fix changes the generated docker command and the image command in x11docker.CMD.sh. My first tests show now issues.

Image x11docker/xfce contains an ENTRYPOINT script that eats up the quotes (same goes for x11docker/lxde). I'll remove that script, it copies files from /etc/skel to HOME. But this has to wait until I push the next x11docker release that does the copy on itself.

Meanwhile you can test e.g.

x11docker -ti -- x11docker/fvwm sh -c "ls -la ; pwd ; sh"

x11docker -i -t x11docker/xfce bash -c "ls && bash" with the note about --clipboard.

The -c is parsed as clipboard option and not used as part of the image command. The correct syntax uses -- to divide x11docker options from image command options: x11docker -i -t -- x11docker/xfce bash -c "ls && bash"

./x11docker -i -t x11docker/xfce ls: does not show the output of ls.

Note that ls in empty HOME does not show any output. Rather check with ls -la

eine commented 5 years ago

I pulled the latest master and I tried:

# ./x11docker -ti -- x11docker/fvwm sh -c "ls -la ; pwd ; sh"
...
Image 'sh' not found locally.
Do you want to pull it from docker hub? [Y|n]
(Will wait up to 60s for a response, otherwise assuming no)y
/c/Users/eine/x11docker/cache/sh-42d07a/dockerrc: line 123: notify-send: command not found
Using default tag: latest
x11docker note: Pulling image sh from docker hub

Error response from daemon: pull access denied for sh, repository does not exist or may require 'docker login'

x11docker ERROR: Did not find image sh.
  Please build image first or pull it from docker hub with:

      docker pull sh

  or run x11docker with option --pull=yes

  Type 'x11docker --help' for usage information
  Debug options: '--verbose' (full log) or '--debug' (log excerpt).
  Logfile will be: /c/Users/eine/x11docker/cache/x11docker.log
  Please report issues at https://github.com/mviereck/x11docker

./x11docker: line 448: /c/Users/eine/x11docker/cache/sh-42d07a/message.log: No such file or directory
./x11docker: line 448: /c/Users/eine/x11docker/cache/sh-42d07a/message.log: No such file or directory
./x11docker: line 448: /c/Users/eine/x11docker/cache/sh-42d07a/message.log: No such file or directory
./x11docker: line 448: /c/Users/eine/x11docker/cache/sh-42d07a/message.log: No such file or directory

But this has to wait until I push the next x11docker release that does the copy on itself.

I'll try with other images meanwhile.

Meanwhile you can test e.g.

 x11docker -ti -- x11docker/fvwm sh -c "ls -la ; pwd ; sh"

I tried, but it fails as shown above. I think that this is related to the fix, rather than to the image. The same happens with x11docker -i -t -- x11docker/xfce bash -c "ls && bash".

The correct syntax uses -- to divide x11docker options from image command options:

I always forget about it when I don't put docker run options. Thanks for the remainder.

mviereck commented 5 years ago

I tried, but it fails as shown above. I think that this is related to the fix, rather than to the image. The same happens with x11docker -i -t -- x11docker/xfce bash -c "ls && bash".

Stupid me, I should have tested without DOCKER_RUN_OPTIONS, too. Is fixed now.

eine commented 5 years ago

It works great now! I believe we can close this too.