有没有比我在下面做的更好的方法来使用Docker做沙盒?

问题描述 投票:0回答:1

我是一个新的Docker用户。我需要做以下事情:

  1. 在我的机器上编译并运行一个随机用户的C ++程序(以及我自己添加的代码)
  2. 捕获输出并在本地处理它。

我正在亚马逊AWS Linux微实例上运行docker。我做了以下事情:

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

在包含我的pre-req文件的不同目录中,我复制了用户的文件。然后我从这个目录构建一个新的docker镜像,使用沙箱基础图像构建。我的Docker文件说:

FROM sandbox
COPY . /sandbox
RUN make

然后我从我的本地环境运行Docker构建命令,如下所示:

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

我将上面的输出捕获到本地文件中,然后使用脚本处理它。

我的问题:这是实现我想要的最佳方式(主要是make和valgrind的输出)吗?

如果我多次迭代地执行此操作,我可以假设每次运行都不会留下要清理的悬空数据(并最终耗尽磁盘空间)吗?

非常感谢你,

&

docker containers sandbox
1个回答
0
投票

如果我多次迭代地执行此操作,我可以假设每次运行都不会留下要清理的悬空数据(并最终耗尽磁盘空间)吗?

您可以保证每次运行都会留下要清理的悬空数据:每个docker build运行都会创建一个新图像,并且这些图像会一直存在,直到被明确删除。这包括完整的valgrind日志文件以及由Makefile构建和生成的任何其他内容。

相反,你可能会考虑是否可以直接使用你的sandbox图像,并使用docker run -v选项注入你想要构建的代码(以及docker run --rm选项,以便在它退出时自动清理容器)。

© www.soinside.com 2019 - 2024. All rights reserved.