『中级篇』手动建立一个base Image(14)
2018-08-27 12:21:31
李明
  • 访问次数: 382
  • 注册日期: 2018-07-09
  • 最后登录: 2022-11-17

原创文章,欢迎转载。转载请注明:转载自 IT人故事会,谢谢!
原文链接地址: 『中级篇』手动建立一个base Image(14)

这篇文章主要介绍了Docker Base Image创建具体实现的相关资料,这里提供了详细的具体步骤,需要的朋友可以参考下github: https://github.com/limingios/docker.git

如何制作一个base Image

base Image 之前讲过2种方式一种是通过pull docker官网获1得,另一种是通过build的方式来获得。自己制作肯定是通过base Image的方式。

  • 通过pull的方式

docker pull hello-world
docker image ls
docker run hello-world

1240

1240

  • 通过build的方式
    1.创建文件

 mkdir hello-world cd hello-world/
 vim hello.c

1240

2.编辑c文件

#include<stdio.h>int main()
{        printf("hello docker  微信公众号:编程坑太多\n");
}

image.png

image.png

3.编译程序gcc

sudo yum install -y gcc
sudo yum install -y glibc-static
 gcc -static hello.c -o hello

image.png

image.png

1240

4.创建编辑Dockerfile

vim Dockfile

1240

FROM scratch
ADD hello /
CMD ["/hello"]

1240

  docker build -t liming/hello .

image.png

image.png

1240

#查看分层layer
   docker history a4cb86cc8d6b

1240

5.运行Image

docker run liming/hello
docker container ls -a

1240


1240

PS:hello.c 因为是c语言写的,我们把它打成一个Image,Image里面其实就是一个可以执行的文件,它其实依赖宿主机kernel,它虽然比较小,但是也能反映docker的架构,后面我们会使用mysql,nginx,tomcat其实他们的原理跟今天做的baseImage 里面的hello 程序是一样的。


李明 最后编辑, 2018-08-27 12:22:22