Clion_connect_docker_and_wsl

Nov 4, 2023

Clion connect docker and wsl

Clion can use remote server, by using target platform environment, Clion can decipher and build delivery. This lesson describer how to consitude such a environment.

Docker

Take docker as an example to illustrate how to setup Clion use remote service as base platform, do compiling / do building / do running.

  • Build Ubuntu image
  • Settings on Clion
  • Sync files

Build Ubuntu image

docker build -t Clion/ubuntu/cpp-env:1.0 -f Dockerfile_cpp-env-ubuntu .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FROM ubuntu:20.04
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get -y install tzdata openssh-server sudo -y
RUN apt-get update \
&& apt-get install -y build-essential \
gcc \
g++ \
gdb \
make \
cmake \
rsync \
gcc-multilib g++-multilib \ # epoll include error
&& apt-get clean
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test
RUN echo 'test:test' | chpasswd
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

After image has built, use this image in docker-compose.yml as below:

1
2
3
4
5
6
7
8
9
10
services:
uu:
container_name: Clion_env
image: Clion/ubuntu/cpp-env:1.0
cap_add:
- SYS_PTRACE
tty: true
ports:
- ${OTHER_PORT}:${OTHER_PORT}
- ${SSH_PORT}:22
1
2
OTHER_PORT=9006
SSH_PORT=2222

Settings on Clion

Settings on clion refer to Build, Execution, Deployment - Toolchains.

Go to Toolchains, press + button to add docker to the list, and fill in Credentials.

clion_remote_settings

Credentials need ports, record on .env file, and user & password is hard code in the docker image.

Tools as CMake / Make / C Compiler / C++ Compiler / Debugger is also hard code in the docker image, so all this needed tools is already present.

After Clion connect to docker container, connected prompt will present, like picture as above.

Here is all about settings on Clion to connect remove server.

Sync files

When files is not correct, you can do a sync file action:

clion_remote_sync_files

wsl - Ubuntu

wsl - Ubuntu is the same as docker. WSL by setting up SSH, download make / cmake / gdb / gcc / c++ tools. Clion do the same as docker stratege to connect to WSL SSH.