docker实践-zombie进程容器

背景:现从事一个容器云产品线的测试工作
场景,假设现在有一个黑客,对产品线进行攻击,在容器云平台上创建了一个容器,容器的启动进程为循环创建zombie进程。
测试点1,容器云产品是否支持僵死进程的stop/ kill
测试点2,容器云产品容器间的隔离性是否足够强,该制造僵死进程的容器是否影响同宿主机上的其他正常用户容器进程的运行。

准备二进制程序

src file:
// zombie_pod.c
// /*  create a zombie process*/
 #include 
 //#include 
 #include 
 #include 
 #include 
 #include 

static void sig_child(int signo)
 {
      pid_t        pid;
      int        stat;
      //处理僵尸进程
      while ((pid = waitpid(-1, &stat, WNOHANG)) >0)
             printf("child %d terminated.\n", pid);
 }
 int main()
 {
     pid_t pid;

        //signal(SIGCHLD,sig_child);
        pid= fork();

        if(pid < 0){
            printf("create child process error!\n");
        }
        else{
            if(pid==0){
                printf("child process %d, father process %d\n",getpid(),getppid());
                exit(0);
            }else{
                printf("current father process, child process:%d, father process:%d\n",getpid(),getppid());
                system("ps -o pid,ppid,state,tty,command\n");
                while(1){
                    sleep(1);
                }
            }
        }


    return 0;
}

gcc编译成可执行程序 zombie

创建dockerfile

1 FROM ubuntu
2 ADD ./zombie /
3 CMD ["/zombie"]

注意⚠️: 1)ADD 指令的第一个参数是Dockerfile文件的相对路径

build 成image

docker build  --tag=cs-kirk/zombie:demo  /Users/shaofangma/code/test/zombie_test/

hh:zombie_test shaofangma$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
cs-kirk/zombie      demo                073718459496        8 seconds ago       130 MB

注意⚠️:build的最后一个参数, 是 Dockerfile所在路径

push到regestry

hh:zombie_test shaofangma$ e

你可能感兴趣的:(云计算)