Running Linux GUI Apps in Docker on Mac
Why would you want to run Linux apps in Docker on a Mac? Maybe there's a Linux program you love or you want the added security of sandboxing an app. Or maybe, as was the case with me, you're developing a C++ program targeting Linux and don't want to cross compile your dependencies.
The following steps get the CLion IDE running in a Docker container created during the project's build process. It uses XQuartz, a version of the X Window system that runs on macOS, along with socat.
- Download the Linux version of CLion
- Each time dependencies change, run
create_dev_container.sh
to create a Docker image and container. The script assumes~/dev
is your code directory. If you use something different, edit the script or run it asCODE_DIR=<your_dir> ./create_dev_container.sh
- Run
start_dev_container.sh
to start the container and exec bash inside of it - From inside the container, run
/home/dev/clion-XXX/bin/clion.sh
to start CLion. If this fails, ensure your container contains a JRE by either manually runningapt install default-jre
or adding it to the Dockerfile. - Either select "Evaluate for free" or enter your activation code
- Open your project
- Build it and enjoy code completion, etc.!
- If you make changes to settings they'll be lost each time you create a new container. To save them, run
docker cp my_project:/root/.CLionXXX/ ~/dev
and import them next time you start CLion in a fresh container.