如何创建或者更新一个image?There are two ways you can update and create images.You can update a container creat
如何创建或者更新一个image?
.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.
第一种,更新一个image并且commit。
# 创建&运行一个container,并开启交互模式$ docker run -t -i training/sinatra /bin/bash# 进入container terminal bash,安装ruby,安装包,退出root@0b2616b0e5a8:/# apt-get install -y ruby2.0-dev ruby2.0root@0b2616b0e5a8:/# gem2.0 install jsonroot@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上。
第二种,使用Dockerfile文件
- 创建一个Dockfile文件
mkdir mydockerbuildcd mydockerbuildtouch Dockerfile
- 打开Dockerfile,并进行编写
FROM docker/whalesay:latest RUN apt-get -y update && apt-get install -y fortunes# CMD /usr/games/fortune -a | cowsay
- build image
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 的账号。然后本地命令行
docker logindocker push yourhubname/docker-whale
添加一个tag
docker tag <imageId>[<imageName>] yourhubname/docker-whale:latest
删除一个image
docker rmi <imageID>[<imageName>]