如何建立或者更新一个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>]