摘要:使用Docker Hub官方gcc:latest鏡像(1.2GB)編譯C/C++程序,以及縮小鏡像的方法。 git
方法1:github
在gcc容器裏編譯C/C++程序 將C/C++代碼運行在gcc容器內的最簡單方法就是將gcc編譯指令寫入Dockerfile中,而後使用此Dockerfile構建自定義C/C++程序鏡像,最後再運行C/C++鏡像。 docker
方法2:ubuntu
在gcc容器外編譯C/C++程序 經過 -v mount數據卷的方法,使用gcc容器編譯宿主主機上的C/C++代碼。 app
若在一個容器中運行了多個進程,可使用 docker top 來查看每一個進程的信息。測試
root@gerryyang:~# docker top 974
UID PID PPID C STIME TTY TIME CMD
root 22879 3128 0 00:18 pts/3 00:00:00 ./myapp
root 22923 22879 0 00:18 pts/3 00:00:00 ./myapp
root@gerryyang:~# docker stop 974
974ui
注意:gcc:latest鏡像很是大,在網上查了下縮小鏡像大小的方法有如下幾種 spa
(1) 在build鏡像時,使用 --rm 選項,Remove intermediate containers after a successful build.net
(2) call a bunch of install commands in one RUN
(3) remove unneeded ubuntu packages
(4) 參考和學習別人的Dockerfile寫法
本文原文地址:https://blog.csdn.net/delphiwcdj/article/details/43235779