新建一个CLion项目(New Project),选择一个模版,例如C++ Executable


到 Settings | Build, Execution, Deployment | Toolchains.
点+,选择Docker

设置Name, Server和Image

(可选)Container Settings,用于X11转发Docker图形界面
Volume bindings: /tmp/.X11-unix , /tmp/.X11-unix
Environment variables: DISPLAY , host.docker.internal:0
Run options: --rm --net=host

到 Settings | Build, Execution, Deployment | CMake.
设置Toolchain为DarkSHINE Docker

Docker内cmake版本为 3.16,需要修改模版里的CMakeList.txt第一行为:
cmake_minimum_required(VERSION 3.16)
Relaod CMake Project、
编译、
运行!