Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use the -v to mapping a device with x11docker? #58

Closed
wanhongbo opened this issue Jul 11, 2018 · 12 comments
Closed

How can I use the -v to mapping a device with x11docker? #58

wanhongbo opened this issue Jul 11, 2018 · 12 comments
Labels

Comments

@wanhongbo
Copy link

When use docker ,I use the "-v /dev/kvm:/dev/kvm" to enable the kvm feature in the conatiner,but use x11docker,threre is no specified paramters,Could you help me?thanks

@eine
Copy link
Contributor

eine commented Jul 11, 2018

You can use docker args/params with the following syntax:

x11docker <x11docker args> -- "<docker args>" <image_name> <container args>

For example:

x11docker --hostdisplay -- "-v $(pwd):/src" 11384eb/sozi sozi

See https://github.com/mviereck/x11docker#terminal-usage


BTW, @mviereck is there any possibility to get rid of double quotes around <docker args>? I'd like commands to be compatible between using GUIs or not. I.e.:

# Works
docker run --rm -it -v $(pwd):/src simexp/octave octave
# Does not work
docker run --rm -it "-v $(pwd):/src" simexp/octave octave
# Does not work (desired)
x11docker --hostdisplay -v $(pwd):/src simexp/octave octave
# Works
x11docker --hostdisplay "-v $(pwd):/src" simexp/octave octave

@wanhongbo
Copy link
Author

It works successfully.Thanks very much!!!

@mviereck
Copy link
Owner

@wanhongbo For mounting a volume at the same location with r/w access, you can also use x11docker option --sharedir /dev/kvm.
Option --sharedir $dir is a shortut for docker run option -v $dir:$dir:rw.

Though, devices should rather be declared with docker run option --device, e.g.

x11docker  --  --device=/dev/kvm  imagename

or

x11docker  --  "--device /dev/kvm"  imagename

@1138-4eb

BTW, @mviereck is there any possibility to get rid of double quotes around ? I'd like commands to be compatible between using GUIs or not.

It is possible if the arguments do not have a whitespace inside. I did not mention it in the documentation to avoid confusion. (While parsing arguments, x11docker takes the first argument after -- without a leading - as imagename.)
Works:

x11docker --  --volume=/dev/kvm:/dev/kvm  imagename

Fails:

x11docker --  -v  /dev/kvm:/dev/kvm  imagename
x11docker --  --volume  /dev/kvm:/dev/kvm  imagename

The issue is to divide between docker run options and imagename+command+args.
I could parse for a second -- to create a syntax like:

x11docker --options  --  --some docker run options -- imagename imagecommand args

This would be an issue if the image command contains --:

x11docker --options  --  imagename imagecommand args1 -- args2

Thoughts?

@eine
Copy link
Contributor

eine commented Jul 11, 2018

It is possible if the arguments do not have a whitespace inside. I did not mention it in the documentation to avoid confusion.

Knowing this is enough for me, as it allows:

x11docker --hostdisplay -- -v=$(pwd):/src -v=/home/user/imgs/:/imgs simexp/octave octave
docker run --rm -it -v=$(pwd):/src -v=/home/user/imgs/:/imgs simexp/octave octave

I'd be ok just adding this to the documentation, even if it is only a side note or a hint.

I could parse for a second -- to create a syntax like:

I think that this would not solve my initial question. Apart from the possible conflict you mention, it would still require the user to remove the additional -- when using the docker CLI.

What I had thought was parsing the docker options explicitly in order to detect the image name. But I think that the current implementation is easier. Since it is compatible already, I don't think it is worth making it more complicated.

@mviereck
Copy link
Owner

mviereck commented Jul 12, 2018

The latest update introduces a new syntax for custom docker run options:

x11docker [OPTIONS] -- DOCKER_RUN_OPTIONS -- IMAGE [COMMAND [ARG1 ARG2 ...]]

Old variants with "" (or without whitespace) are still valid, with only one exception if the image command contained -- and also docker run options were given.
Changelog entry:

     New:
   x11docker [OPTIONS] --  DOCKER_RUN_OPTIONS -- IMAGE [COMMAND [ARG1 ARG2 ...]]
     Previous, still valid:
   x11docker [OPTIONS] -- "DOCKER_RUN_OPTIONS"   IMAGE [COMMAND [ARG1 ARG2 ...]]
   x11docker [OPTIONS] -- IMAGE COMMAND ARG1 -- ARG2
     BREAKS due to wrongly parsed -- :
   x11docker [OPTIONS] -- "DOCKER_RUN_OPTIONS"   IMAGE COMMAND ARG1 -- ARG2

it would still require the user to remove the additional -- when using the docker CLI.

No, docker CLI accepts -- between options and image name.
You can use the same syntax for docker and x11docker.

@eine
Copy link
Contributor

eine commented Jul 30, 2018

@mviereck is x11docker [OPTIONS] -- "DOCKER_RUN_OPTIONS" -- IMAGE COMMAND ARG1 -- ARG2 valid as a workaround for the wrongly parsed format?

@mviereck
Copy link
Owner

mviereck commented Jul 30, 2018

It should be valid with and without "". Though, just found that x11docker parses it wrong.
Maybe you have an idea how to fix it. Current issue: x11docker drops the part IMAGE COMMAND ARG1.

On first occurence of -- (and a following arg beginning with -), x11docker tries to split the remaining string at the second --.

This part correctly parses DOCKER_RUN_OPTIONS (aaa):

echo "aaa -- bbb -- ccc" | sed 's/ -- .*//'

This should return bbb -- ccc, but only returns ccc:

echo "aaa -- bbb -- ccc" | sed  -n 's/^.* -- //p'

Edit: Fixed it without sed:

Line="aaa -- bbb -- ccc" 
Line="${Line#aaa -- }"

@eine
Copy link
Contributor

eine commented Jul 31, 2018

I saw that you solved without sed. But, just for completeness:

$ echo "aaa -- bbb -- ccc" | sed  -e 's/^[^-]* --//g'
 bbb -- ccc

$ echo "aaa -- bbb -- ccc" | sed  -e 's/^[^-]* --\s*//g'
bbb -- ccc

@mviereck
Copy link
Owner

mviereck commented Jul 31, 2018

saw that you solved without sed

I would prefer to solve it with sed. The bash string operation is quite sensitive to every difference, a wrongly parsed whitespace would already lead to wrong results.

I tried your code examples with more complex strings:

$ echo "--some --run option -- image --arg1 -- --arg2" | sed  -e 's/^[^-]* -- //g'
--some --run option -- image --arg1 -- --arg2
$ echo "--some --run option -- image --arg1 -- --arg2" | sed  -e 's/^[^-]* --\s*//g'
--some --run option -- image --arg1 -- --arg2

It does not divide between -- of an --option and the separator -- with a leading and a trailing whitespace .

Can you do some sed magic that can handle this?

@eine
Copy link
Contributor

eine commented Aug 2, 2018

I could make it work in https://regexr.com/. If you put /^.*?(?=\s--\s) -- /gm in the expression, the following text:

--some --run option -- image --arg1 -- --arg2
aaa -- bbb -- ccc

will produce this output in 'Replace' mode:

image --arg1 -- --arg2
bbb -- ccc

But I could not reproduce it in the bash (neither cygwin nor MSYS).

@mviereck
Copy link
Owner

mviereck commented Aug 2, 2018

I've asked in a forum and got this one, works quite well: sed -E 's/.* -- (.*( --.*))/\1/'

@mviereck
Copy link
Owner

mviereck commented Aug 4, 2018

The snippet above fails for more -- separators:

$ echo "aaa -- bbb -- ccc -- ddd" | sed -E 's/.* -- (.*( --.*))/\1/'
ccc -- ddd

I got some more possible code snippets. Now x11docker uses:

$ sh -c 'echo "${0#* -- }"' "aaa -- bbb -- ccc -- ddd"
bbb -- ccc -- ddd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants