【转载】使用Docker Hub官方gcc:latest镜像编译C/C++程序以及缩小镜像的方法

摘要:使用Docker Hub官方gcc:latest镜像(1.2GB)编译C/C++程序,以及缩小镜像的方法。

方法1:

在gcc容器里编译C/C++程序 将C/C++代码运行在gcc容器内的最简单方法就是将gcc编译指令写入Dockerfile中,然后使用此Dockerfile构建自定义C/C++程序镜像,最后再运行C/C++镜像。

方法2:

在gcc容器外编译C/C++程序 通过 -v mount数据卷的方法,使用gcc容器编译宿主主机上的C/C++代码。

本文测试代码请见GitHub

若在一个容器中运行了多个进程,可以使用 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
974

注意:gcc:latest镜像非常大,在网上查了下缩小镜像大小的方法有以下几种

(1) 在build镜像时,使用 --rm 选项,Remove intermediate containers after a successful build

(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

猜你喜欢

转载自www.cnblogs.com/hailun1987/p/9697283.html
今日推荐