請參考:[https://www.jianshu.com/p/665...]c++
#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; }
FROM centos RUN yum install -y gcc gcc-c++ make patch sudo RUN mkdir /usr/src/docker_test COPY docker_test.cpp /usr/src/docker_test WORKDIR /usr/src/docker_test RUN g++ -o test docker_test.cpp CMD ["./test"]
$sudo docker build -t docker-test:v1 .
$sudo docker images REPOSITORY TAG IMAGE ID SIZE docker-test v1 ba22adea3409 399MB $sudo docker run -d docker-test:v1
##2.5 進入/退出dockerdocker
$ sudo docker ps CONTAINER ID IMAGE COMMAND a13f3b550314 docker-test:v1 "./test" $ sudo docker exec -it f7fff670a3a4 /bin/bash $ cd /usr/src/docker_test/ $ ls docker_test.cpp docker_test.txt test $exit