我們可以上傳映像檔,並在其他地方運行,registry是repository的集合,而repository是image的集合,類似於GitHub repository。
$ docker login
用於將本地映像與registry上的repository關聯的表示法是username / repository:tag
。tag
是選填的,但官方文件建議加上tag
,因為它是用於記錄版本的。
$ docker tag image username/repository:tag
執行docker image ls
來檢視新增的映像檔
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
friendlyhello latest d9e555c53008 3 minutes ago 195MB
gordon/get-started part2 d9e555c53008 3 minutes ago 195MB
python 2.7-slim 1c7128a655f6 5 days ago 183MB
...
上傳映像檔:
$ docker push username/repository:tag
執行映像檔:
$ docker run -p 4000:80 username/repository:tag
如果本地端沒有該映像檔,Docker會從repository抓取:
$ docker run -p 4000:80 gordon/get-started:part2
Unable to find image 'gordon/get-started:part2' locally
part2: Pulling from gordon/get-started
10a267c67f42: Already exists
f68a39a6a5e4: Already exists
9beaffc0cf19: Already exists
3c1fe835fb6b: Already exists
4c9f1fa8fcb8: Already exists
ee7d8f576a14: Already exists
fbccdcced46e: Already exists
Digest: sha256:0601c866aab2adcc6498200efd0f754037e909e5fd42069adeff72d1e2439068
Status: Downloaded newer image for gordon/get-started:part2
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)