flame

路漫漫其修远兮 吾将上下而求索

0%

c项目开发环境-基于docker和clion

前言

基于docker和clion的c项目开发环境

docker

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update

RUN apt-get install -y tzdata
RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN dpkg-reconfigure --frontend noninteractive tzdata

RUN apt-get install -y ssh
RUN apt-get install -y build-essential
RUN apt-get install -y gcc
RUN apt-get install -y g++
RUN apt-get install -y gdb
RUN apt-get install -y clang
RUN apt-get install -y cmake
RUN apt-get install -y automake
RUN apt-get install -y pkg-config
RUN apt-get install -y rsync
RUN apt-get install -y tar
RUN apt-get install -y python
RUN apt-get install -y vim
RUN apt-get install -y sudo

RUN apt-get clean autoclean



RUN yes root | passwd root
RUN useradd -m clion
RUN yes clion | passwd clion
RUN mkdir /run/sshd

RUN ( \
echo 'PermitRootLogin yes'; \
echo 'PasswordAuthentication yes'; \
echo 'Subsystem sftp /usr/lib/openssh/sftp-server'; \
) > /etc/ssh/sshd_config_test_clion

CMD ["/usr/sbin/sshd", "-D", "-e", "-f", "/etc/ssh/sshd_config_test_clion"]

构建镜像

1
docker build -t c-env/c_remote_env:0.1 -f Dockerfile  .

启动容器

1
docker run -it -d --cap-add sys_ptrace -p127.0.0.1:2222:22 --name clion_remote_env --hostname clion-remote-machine c-env/c_remote_env:0.1

登录

ssh登录 用户名:clion 密码:clion

1
ssh clion@127.0.0.1 -p 2222

ssh登录 用户名:root 密码:root 端口:2222

1
ssh root@127.0.0.1 -p 2222

docker登录

1
docker exec -it clion_remote_env /bin/bash

clion

clion设置

Toolchains选项

clion toolchains选项

添加CMake选项

clion CMake选项

clion本地调试

clion local debug

clion远程调试

clion remote debug

项目实现

项目实现

reference

Using Docker with CLion

docker –cap-add

linux capabilities

Clion利用Docker开发和调试Linux C/C++程序