CLion + Docker + X11 forwarding

Answered

I'm running CLion 2021.3.3, to which I am very new.  I do all my development with Docker and am trying to stand up a new CMake project to create a simple 2D plot using https://github.com/lava/matplotlib-cpp.  I want to build this project using the Docker toolchain (which I set up using instructions from here https://www.youtube.com/watch?v=p7Bi-mOyelM).  I am able to build and run an exec built from the following:

#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;

int main() {
plt::plot({1,3,2,4});
plt::show();
return 0;
}

using my run configuration that uses the Docker toolchain and a container derived from my Docker image, however, I don't see the expected plot window pop-up.

This seems like a really simple use case but I can't seem to find posts on SO or JB forums that address anything close to what I am trying to do.  In my homegrown setups, I would just launch a dev container using the following

docker run -it --rm \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e DISPLAY=$DISPLAY \
    --name some-name \
    --net host \
    --privileged \
    some-image

after configuring my interactive bash sessions with xhost +local:docker.  Then, I'd compile and run my application and I'd see the plot windows appear using my host's x11 server. 

Put simply: What's the best way to build and run applications that create graphics using CLion and the Docker toolchain?

2 comments
Comment actions Permalink

Hello!

In CLion 2022.1 EAP you can now provide additional container settings, such as port and volume bindings, and others - https://blog.jetbrains.com/clion/2022/01/clion-starts-the-2022-1-eap/#Docker_toolchain.

Maybe it will be useful in your case.

1
Comment actions Permalink

Anna Falevskaya can confirm that the EAP gives me the desired configurability for the docker runtime.  Thanks for the tip!

0

Please sign in to leave a comment.