How do I pull the clipboard out of a Docker container?

I have Vim installed inside a docker container.

I want to rip out some text and somehow magically make it available on my host's clipboard (macOS).

Is it possible?

UPDATE

So, to clarify, this is my full use case ...

  • docker run ...

    some container with Vim baked into an image
  • CMD by default will turn me to bash shell
  • I am mounting an application directory from my host (macOS) into a container
  • from container i run vim, write code
  • from vim I want to rip out some text and use it in both:
    • docker system clipboard (so I can paste it into the container shell if I want)
    • the host's system clipboard (macOS) (so I can paste it into other host programs, TextEdit or email, whatever)

Now I'm not sure how it works in a host sense (macOS) to use the virtual machine provided by the docker ecosystem to start docker first (since macOS is not a Linux based system and as such cannot start docker containers natively without an intermediate virtual machine ).

So I'm not sure if the tricks for getting content to the docker system clipboard will be filtered back to the VM and to the actual (macOS) host.

x11

I've seen people suggest using X11 and mounting the socket file into a docker container and then using xclip (or xsel). I tried this, but couldn't get Vim to crawl into the appropriate register for xclip to pick up the tweaked content. So afterwards I was not sure if my attempt to install and mount x11 also worked:

  • brew install Caskroom/cask/xquartz

  • open -a XQuartz

  • as part of running docker -v /tmp/.X11-unix:/tmp/.X11-unix

  • from container apt-get install -y xclip

  • from vim in a container "*yiw

    (select the selection case "*

    and then yiw

    keep the current word under the cursor) <but it seems that vim 8 inside the container has no such case to be captured? my vimrc that I mounted in the container already has it set clipboard+=unnamed

    (this is what I have used in the past to get vim to load into the macOS system clipboard).

Note. If I tried to use xclip

directly (just to see how it works), most of what I tried resulted in Error: Can't open display: (null)

.

+3


source to share


1 answer


It definitely is.

Take a look at https://github.com/wincent/clipper



It is a service that allows you to write to the clipboard using netcat

.

All you would need to do is access your localhost inside a docker container .

+1


source







All Articles