docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest fce289e99eb9 12 months ago 1.84kB ubuntu 12.04 5b117edd0b76 2 years ago 104MB
在終端機列出訊息中,可以看到幾段文字訊息
REPOSITORY:來自哪個 Registry
TAG:版本
IMAGE ID:Image 的 ID(唯一)
CREATED:建立時間
VIRTUAL SIZE:Image 檔案大小
題外話:可以看到 hello-world 的 TAG 是 latest,這代表著這個 Image 沒有設定 TAG,恩…
建立 Docker Image
修改別人的 Image 已建立新的 Image
首先,先把別人的 Image pull 下來並啟動 Container
1 2 3 4 5 6 7 8 9 10 11 12 13 14
docker run -t -i training/sinatra /bin/bash
Unable to find image 'training/sinatra:latest' locally latest: Pulling from training/sinatra Image docker.io/training/sinatra:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/ a3ed95caeb02: Pull complete 6e71c809542e: Pull complete d196a7609355: Pull complete 08f6dff5acea: Pull complete ce65532003d0: Pull complete 54bcaa4d1a10: Pull complete 8572ad96f6e1: Pull complete Digest: ... Status: Downloaded newer image for training/sinatra:latest
稍微對這個別人的 Image 對點手腳,加個 gem install json 為例來試試
1 2 3 4 5 6 7 8
root@360d0440d1d4:/# gem install json
Fetching: json-2.3.0.gem (100%) Building native extensions. This could take a while... Successfully installed json-2.3.0 1 gem installed Installing ri documentation for json-2.3.0... Installing RDoc documentation for json-2.3.0...
7c61f457e695:Container ID,透過 docker ps / docker ps -a 取得
chestertang/sinatra:v2:v2 冒號前半段是 Repository 名稱(不能大寫),後半段是 TAG
再來看看 docker images 吧!
1 2 3 4 5 6
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE chestertang/sinatra v2 3bae0e76683f 11 seconds ago 447MB ubuntu 12.04 5b117edd0b76 2 years ago 104MB training/sinatra latest 49d952a36c58 5 years ago 447MB
# This is a comment FROM ubuntu:14.04 MAINTAINER Docker Chester <[email protected]> RUN apt-get -qq update RUN apt-get -qqy install ruby ruby-dev RUN gem install sinatra
Dockerfile 的基本語法的思如下:
# 來表示註解
FROM 指令告訴 Docker 使用哪個 Image 作為基底
MAINTAINER 表示誰是這個 file 的維護者
RUN 開頭的指令會在建立中執行,比如在這裏使用 apt-get 來安裝 ruby、sinatra 套件
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES 83be203c6040 chestertang/sinatra:v2 "/bin/bash" 48 minutes ago Exited (0) 18 minutes ago elastic_hertz 2f902d9238f5 chestertang/sinatra:v2 "/bin/bash" 4 days ago Exited (130) 4 days ago confident_ritchie d7b639b8385a ubuntu:12.04 "/bin/bash" 7 days ago Exited (127) 7 days ago dreamy_hypatia 1d8d58333b3d ubuntu:12.04 "/bin/bash" 7 days ago Exited (130) 7 days ago wizardly_morse c9a19d3553c9 ubuntu:12.04 "/bin/bash" 7 days ago Exited (0) 7 days ago interesting_dubinsky bcf468d00ca2 hello-world "/hello" 9 days ago Exited (0) 9 days ago inspiring_newton
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE chestertang/sinatra v2 3bae0e76683f 7 days ago 447MB ubuntu 14.04 6e4f1fe62ff1 5 weeks ago 197MB hello-world latest fce289e99eb9 13 months ago 1.84kB ubuntu 12.04 5b117edd0b76 2 years ago 104MB joshhu/webdemo latest c58bf6158823 4 years ago 243MB training/sinatra latest 49d952a36c58 5 years ago 447MB