1. docker安装
请参考:[https://www.jianshu.com/p/665...]
2.制作docker镜像
2.1 准备测试程序docker_test.cpp
#include <stdio.h>#include <unistd.h>#include <string.h>int main(int argc, char** args){ FILE* pfile = fopen("docker_test.txt", "wb"); if(NULL == pfile) { return 0; } char buf[50] = "hello, welcome to learn docker"; while(1) { printf(buf); fwrite(buf, 1, strlen(buf), pfile); sleep(1); } return 0;}
2.2 编写docker文件
FROM centosRUN yum install -y gcc gcc-c++ make patch sudoRUN mkdir /usr/src/docker_testCOPY docker_test.cpp /usr/src/docker_testWORKDIR /usr/src/docker_testRUN g++ -o test docker_test.cppCMD ["./test"]
2.3 编译
$sudo docker build -t docker-test:v1 .
2.4 运行docker镜像
$sudo docker imagesREPOSITORY TAG IMAGE ID SIZEdocker-test v1 ba22adea3409 399MB$sudo docker run -d docker-test:v1
##2.5 进入/退出docker
$ sudo docker psCONTAINER ID IMAGE COMMAND a13f3b550314 docker-test:v1 "./test"$ sudo docker exec -it f7fff670a3a4 /bin/bash$ cd /usr/src/docker_test/$ lsdocker_test.cpp docker_test.txt test$exit