自己build 一個docker hello的image
阿新 • • 發佈:2018-11-10
環境ubuntu 18.04
安裝docker
sudo apt update
sudo apt install docker.io
centos
yum install docker.io
接下來寫一個hello程式 並編譯成二進位制
#include<stdio.h>
int main()
{
printf("hello\n");
}
$gcc hello.c -o hello
編輯Dockerfile
FROM scratch #從哪個映象引入 ADD hello / #將檔案新增進根目錄 CMD ["/hello"] #程式
生成image 檢視並執行
docker build -t hpb/hello .
檢視
[[email protected] hello]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
hello latest 85f4d25d3523 35 minutes ago 8.44 kB
run
docker run hello hello
run