{"id":275,"title":"Diy\u4e00\u4e2aBase image","good":0,"bad":0,"hit":2198,"created_at":"2018-04-26 17:19:48","content":"
<\/p>
\u5efa\u7acb\u76ee\u5f55\uff1a<\/p>
[root@iZwz99m0qp1swglw9om6zxZ docker]# pwd<\/p>
\/root\/docker<\/p>
[root@iZwz99m0qp1swglw9om6zxZ docker]# mkdir hurong-first-docker<\/p>
[root@iZwz99m0qp1swglw9om6zxZ docker]# ls<\/p>
hurong-first-docker<\/p>
[root@iZwz99m0qp1swglw9om6zxZ docker]# cd hurong-first-docker\/<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# <\/p>
<\/p>
\u5efa\u7acb\u4e00\u4e2ac\u7a0b\u5e8f
<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# vim hello.c<\/p>
#include<stdio.h><\/p>
int main(){<\/p>
printf("this is hurong's first docker imagen");<\/p>
}<\/p>
\u7f16\u8bd1\u524d\u9700\u8981\u5b89\u88c5\uff08\u5982\u679c\u6ca1\u5b89\u88c5\u7684\u8bdd\uff09
<\/p>
(sudo) yum install gcc<\/p>
(sudo) yum install glibc-static<\/p>
\u7f16\u8bd1\u5b8c\u6210\u540e\u4f1a\u591a\u4e86\u4e00\u4e2ahello\u6587\u4ef6<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# gcc -static hello.c -o hello<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# ls<\/p>
hello hello.c<\/p>
\u76f4\u63a5\u8fd0\u884c\u53ef\u4ee5\u67e5\u770b\u6548\u679c\uff1a<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# .\/hello <\/p>
this is hurong's first docker image<\/p>
\u51c6\u5907\u751f\u6210\u955c\u50cf\u6587\u4ef6\uff1a
<\/p>
\u5728Dockerfile\u4e2d\u5199\u5165\uff1a<\/p>
FROM scratch<\/p>
ADD hello \/<\/p>
CMD ["\/hello"]<\/p>
\u8bf4\u660e\uff1a<\/p>
\u7b2c1\u884c\u8868\u793a\u4ece\u54ea\u4e2a\u955c\u50cf\uff0c\u7531\u4e8e\u662f\u81ea\u5df1\u7684\u7b2c\u4e00\u4e2a\u57fa\u7840\u955c\u50cf\uff0c\u6240\u4ee5\u5199scratch<\/p>
\u7b2c2\u884c\u8868\u793a\u5c06\u7f16\u8bd1\u7684hello\u6253\u5305\u5230\u955c\u50cf\u7684\u6839\u76ee\u5f55<\/p>
\u7b2c3\u884c\u8868\u793a\u5bb9\u5668\u542f\u52a8\u540e\u6267\u884c\u6839\u76ee\u5f55\u4e0b\u7684hello\u7a0b\u5e8f<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# vim Dockerfile<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# ls<\/p>
Dockerfile hello hello.c<\/p>
<\/p>
\u6784\u5efa\u955c\u50cf\uff1a<\/p>
docker build -t hurong .<\/p>
-t\u540e\u9762\u662f\u955c\u50cf\u540d\uff0c\u70b9\u662f\u5f53\u524d\u76ee\u5f55\uff0c\u8868\u793a\u4ece\u5f53\u524d\u76ee\u5f55\u6784\u5efa<\/p>
<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# docker build -t hurong .<\/p>
Sending build context to Docker daemon 847.9kB<\/p>
Step 1\/3 : FROM scratch<\/p>
---> <\/p>
Step 2\/3 : ADD hello \/<\/p>
---> 4e8c5c2ab049<\/p>
Step 3\/3 : CMD ["\/hello"]<\/p>
---> Running in fef58c716e36<\/p>
Removing intermediate container fef58c716e36<\/p>
---> 5e574987d1c6<\/p>
Successfully built 5e574987d1c6<\/p>
Successfully tagged hurong:latest<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# <\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# ls<\/p>
Dockerfile hello hello.c<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# docker image list<\/p>
REPOSITORY TAG IMAGE ID CREATED SIZE<\/p>
hurong latest 5e574987d1c6 About a minute ago 844kB<\/p>
hello-world latest e38bc07ac18e 2 weeks ago 1.85kB<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# <\/p>
\u8fd0\u884c\u8bd5\u8bd5\uff1a<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# docker run hurong<\/p>
this is hurong's first docker image<\/p>
<\/p>
\u67e5\u770bdocker\u955c\u50cf\u5206\u5c42\uff1a<\/p>
docker history IMAGE\u3000ID<\/p>
[root@iZwz99m0qp1swglw9om6zxZ hurong-first-docker]# docker history 5e574987d1c6<\/p>
IMAGE CREATED CREATED BY SIZE COMMENT<\/p>
5e574987d1c6 3 minutes ago \/bin\/sh -c #(nop) CMD ["\/hello"] 0B <\/p>
4e8c5c2ab049 3 minutes ago \/bin\/sh -c #(nop) ADD file:ea6276e5b0554f41b\u2026 844kB <\/p>
<\/p>
\u4e0a\u9762\u53ef\u4ee5\u770b\u5230\u8fd9\u4e2a\u955c\u50cf\u6dfb\u52a0\u4e86\u4e00\u4e2a\u6587\u4ef6\uff0c\u7136\u540e\u6267\u884c\u6839\u76ee\u5f55\u4e0b\u7684hello\u7a0b\u5e8f<\/p>"}