[C/C++開發] Clion利用Docker開發和調試Linux C/C++程序


本文章以C++為例講解Clion利用Docker開發和調試Linux C/C++程序。使用的Clion版本為2020.1

 

參考文章

Clion 如何使用 Docker 作為開發環境 (主要參考)

Using Docker with CLion

clion遠程到ubuntu的docker環境編譯調試

利用Docker和CLion在Mac優雅地開發和調試Linux C++程序

跨平台IDE集成開發環境Clion教程:將Docker與CLion結合使用

Dockerize an SSH service

https://www.jetbrains.com/help/clion/remote-debug.html#remote-config

https://www.jetbrains.com/help/clion/cmake-profile.html

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004359599-Cmake-profile-not-found

 

構建docker鏡像

dockerfile

# @description php image base on the alpine edge
#                       some information
# ------------------------------------------------------------------------------------
# @link https://hub.docker.com/_/alpine/      alpine image
# @link https://hub.docker.com/_/php/         php image
# @link https://github.com/docker-library/php php dockerfiles
# ------------------------------------------------------------------------------------
# @build-example docker build . -f Dockerfile -t mydev/ubuntu:1.0.0
# 


FROM ubuntu:latest

RUN export DEBIAN_FRONTEND=noninteractive \
    && apt-get update \
    && apt-get install -y tzdata \
    && ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && dpkg-reconfigure --frontend noninteractive tzdata

RUN apt-get update && apt-get install -y \
ssh \
build-essential \
gcc \
g++ \
gdb \
clang \
cmake \
rsync \
tar \
python \
vim \
automake \
openssh-client \
openssh-server \
pkg-config \
libxml2-dev \
libsqlite3-dev \
&& apt-get clean

RUN apt-get install sudo

RUN echo "#!/bin/bash\nadduser deploy << EOF\npassword\npassword\ndeploy\n\n\n\nY\nEOF" >> create_deploy.sh \
    && chmod 755 create_deploy.sh \
    && ./create_deploy.sh \
    && gpasswd -a deploy sudo \
    && rm create_deploy.sh \
    && chmod 644 /etc/sudoers \
    && echo "deploy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
    && passwd deploy

以上鏡像,做了幾個事情要提一下

1. 安裝了ssh客戶端

2. 建立了linux用戶,賬號: deploy,密碼: deploy

 

構建

docker build . -f Dockerfile -t mydev/ubuntu:1.0.0

 

 

運行容器

docker-compose.yml

version: '3.4' 

services:
  mydevubuntu:
    image: mydev/ubuntu:1.0.0
    container_name: mydevubuntu
    ports: 
      - "2222:22"
      - "2223:2223"
    networks:
      # create the docker network first: docker network create local_default_network
      - local_default_network
      # create the docker network first: docker network create pp_service_network
      - pp_service_network
    volumes:
      - /System/Volumes/Data/Software/Project/pipi:/System/Volumes/Data/Software/Project/pipi
    stdin_open: true
    tty: true
    privileged: true
    security_opt:
      - seccomp:unconfined
    command:
      bash -c "/etc/init.d/ssh restart && tail -f /dev/null"

networks:
  local_default_network:
    external: true
  pp_service_network:
    external: true

 

運行容器

 

項目相關

創建項目

 

 

Toolchains 設置

Settings-Build, Execution, Deployment-Toolchains

 

 

 

Settings-Build, Execution, Deployment-CMake

 

 

Settings-Build, Execution, Deployment-Deployment

 

 

 

遠程debug配置

 

 

 

 

 

來了來了,他來了

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM