如何建立或者更新一個image?docker
There are two ways you can update and create images.
You can update a container created from an image and commit the results to an image.
You can use a Dockerfile to specify instructions to create an image.json
第一種,更新一個image而且commit。ruby
# 建立&運行一個container,並開啓交互模式 $ docker run -t -i training/sinatra /bin/bash # 進入container terminal bash,安裝ruby,安裝包,退出 root@0b2616b0e5a8:/# apt-get install -y ruby2.0-dev ruby2.0 root@0b2616b0e5a8:/# gem2.0 install json root@0b2616b0e5a8:/# exit # 提交變動,-m message/ -a author,containerId, commit後的image name $ docker commit -m "Added json gem" -a "Kate Smith" 0b2616b0e5a8 ouruser/sinatra:v2
commit以後在本地images中就能夠看見ouruser/sinatra:v2的image了,以後能夠選擇從這個image來建立一個新的container,或者將其push到docker bub上。bash
第二種,使用Dockerfile文件ui
mkdir mydockerbuild cd mydockerbuild touch Dockerfile
FROM docker/whalesay:latest RUN apt-get -y update && apt-get install -y fortunes # CMD /usr/games/fortune -a | cowsay
docker build -t docker-whale .
The docker build -t docker-whale . command takes the Dockerfile in the current directory, and builds an image called docker-whale on your local machine.命令行
附: 若是須要將image發佈到docker hub上,首先須要sign up一個 docker hub 的帳號。 而後本地命令行code
docker login docker push yourhubname/docker-whale
添加一個tagci
docker tag <imageId>[<imageName>] yourhubname/docker-whale:latest
刪除一個imageterminal
docker rmi <imageID>[<imageName>]