社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

有没有比我下面做的更好的方法来处理Docker的沙箱?

Av Filter • 6 年前 • 2053 次点击  

  1. 在我的机器上编译和运行一个随机用户C++程序 加上我自己的代码)

我在Amazon AWS Linux微实例上运行docker。我做了以下工作:

定制并构建了一个名为sandbox的Ubuntu映像,其中包含了我需要的所有软件包(g++、valgrind、make等)

在包含我的pre-req文件的另一个目录中,我复制用户文件。然后我从这个目录中构建一个新的docker映像,这个目录使用沙盒基础映像构建。我的卷宗上写着:

FROM sandbox
COPY . /sandbox
RUN make

307 {aws-028}testcpp: docker build --tag=test .
Sending build context to Docker daemon  35.33kB
Step 1/5 : FROM        sandbox
 ---> 42fdf2be6912
Step 2/5 : MAINTAINER  AVFILT
 ---> Running in d5531528333c
Removing intermediate container d5531528333c
 ---> 561070a04095
Step 3/5 : WORKDIR /sandbox
 ---> Running in 7d1afb32f3ef
Removing intermediate container 7d1afb32f3ef
 ---> e416508e5180
Step 4/5 : COPY . /sandbox
 ---> 8392a378a6a2
Step 5/5 : RUN make
 ---> Running in bf041f3a5353
g++ -Wall -O0 -std=c++0x *.cpp 
valgrind ./a.out  # >a.log 2>&1
==22== Memcheck, a memory error detector
==22== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==22== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==22== Command: ./a.out
==22== 
Success. All tests passed. Congratulations.
==22== 
==22== HEAP SUMMARY:
==22==     in use at exit: 72,704 bytes in 1 blocks
==22==   total heap usage: 3,881 allocs, 3,880 frees, 524,711 bytes allocated
==22== 
==22== LEAK SUMMARY:
==22==    definitely lost: 0 bytes in 0 blocks
==22==    indirectly lost: 0 bytes in 0 blocks
==22==      possibly lost: 0 bytes in 0 blocks
==22==    still reachable: 72,704 bytes in 1 blocks
==22==         suppressed: 0 bytes in 0 blocks
==22== Rerun with --leak-check=full to see details of leaked memory
==22== 
==22== For counts of detected and suppressed errors, rerun with: -v
==22== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Removing intermediate container bf041f3a5353
 ---> 9cf23028b470
Successfully built 9cf23028b470
Successfully tagged test:latest

我将上述输出捕获到一个本地文件中,然后使用脚本对其进行处理。

如果我反复多次这样做,我能不能假设每次运行都不会留下待清理的悬挂数据(最终耗尽磁盘空间)?

非常感谢你,

&安培;

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53627
文章 [ 1 ]  |  最新文章 6 年前
David Maze
Reply   •   1 楼
David Maze    7 年前

如果我反复多次这样做,我能不能假设每次运行都不会留下待清理的悬挂数据(最终耗尽磁盘空间)?

你保证每次跑步 留下待清理的悬挂数据:每个 docker build run创建一个新的图像,这些图像将一直保留到显式删除。包括完整的valgrind日志文件以及 Makefile

相反,您可以考虑是否可以直接使用 sandbox 图像,并使用 docker run -v docker run --rm 选项,当容器退出时自动清理容器。