打造自己的hello-world docker镜像

2020-02-24  本文已影响0人  JohnYuCN

一、用c打造自己的hello-world

  1. vim 打开main.c
root@ali001:~# mkdir demo1 && cd demo1 && vim main.c
  1. main.c的代码
#include <stdio.h>

int main(){
        printf("hello world!\n");
        return 0;
}
  1. 静态编译
root@ali001:~#  gcc -static main.c -o hello

现在你拥有了一个执行程序。

二、创建镜像

  1. 编写自己的Dockerfile
FROM scratch
ADD hello /
CMD ["/hello"]           
  1. 创建
root@ali001:~#  docker build -t johnyucn/hello-world
  1. 运行:
docker run johnyucn/hello-world
上一篇 下一篇

猜你喜欢

热点阅读