打包一個Docker鏡像,讓你的好友載入開啟一個容器,並且每隔一秒輸出hello,world到指定的檔案中,

來源:互聯網
上載者:User

打包一個Docker鏡像,讓你的好友載入開啟一個容器,並且每隔一秒輸出hello,world到指定的檔案中,

一、兩個指令碼代碼

Dockerfile

1 FROM bash2 COPY . /usr/herui/3 WORKDIR /usr/herui/4 CMD [ "sh", "hello_world.sh" ]

hello_world.sh

1 #!/bin/bash2 while true3 do4 echo 'hello world!' >> /usr/herui/hello_world.log5 sleep 16 done

 

二、打包成鏡像

1、

 1 [root@localhost herui]# docker build -t hello_world:1.01 2 "docker build" requires exactly 1 argument(s). 3 See 'docker build --help'. 4  5 Usage:  docker build [OPTIONS] PATH | URL | - 6  7 Build an image from a Dockerfile 8 [root@localhost herui]# docker build -t hello_world:1.01 . 9 Sending build context to Docker daemon  3.072kB10 Step 1/4 : FROM bash11  ---> 906f4bf24f0012 Step 2/4 : COPY . /usr/herui/13  ---> Using cache14  ---> ab38183c9bcb15 Step 3/4 : WORKDIR /usr/herui/16  ---> Using cache17  ---> 24442df0587c18 Step 4/4 : CMD sh hello_world.sh19  ---> Using cache20  ---> 9413de166e6f21 Successfully built 9413de166e6f22 Successfully tagged hello_world:1.01

這裡要注意,打包指令需要在Dockerfile、hello_world.sh下進行,指令後面最後一個“.”,這叫上下文路徑。

2、查看鏡像檔案列表,看看是否成功

1 [root@localhost herui]# docker images2 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE3 hello_world         1.01                9413de166e6f        2 days ago          12.1MB

 

三、儲存成tar.gz格式並檢查目前的目錄下包是否存在

1 [root@localhost herui# docker save hello_world:1.01 | gzip > hello_world.tar.gz2 [root@localhost herui]# ls -lh hello_*3 -rw-r--r--. 1 root root   92 Aug 31 17:53 hello_world.sh4 -rw-r--r--. 1 root root 4.4M Sep  3 01:29 hello_world.tar.gz

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.