更新镜像
更新镜像之前,我们需要使用镜像来创建一个容器:
lusifer@UbuntuBase:~$ docker run -it ubuntu:15.10 /bin/bash
root@9a3dcafd7a83:/# apt-get update
Ign http://archive.ubuntu.com wily InRelease
Ign http://archive.ubuntu.com wily-updates InRelease
Ign http://archive.ubuntu.com wily-security InRelease
Ign http://archive.ubuntu.com wily Release.gpg
Ign http://archive.ubuntu.com wily-updates Release.gpg
Ign http://archive.ubuntu.com wily-security Release.gpg
Ign http://archive.ubuntu.com wily Release
Ign http://archive.ubuntu.com wily-updates Release
Ign http://archive.ubuntu.com wily-security Release
在运行的容器内使用 apt-get update
命令进行更新。
在完成操作之后,输入 exit
命令来退出这个容器。
此时ID为 9a3dcafd7a83
的容器,是按我们的需求更改的容器。我们可以通过命令 docker commit
来提交容器副本。
lusifer@UbuntuBase:~$ docker commit -m="has update" -a="lusifer" 9a3dcafd7a83 lusifer/ubuntu:v2
sha256:2642b4944b285974e5f007f30bc33b651220ea9931982c3c53b61a8f8fd5011b
各个参数说明:
- -m:提交的描述信息
- -a:指定镜像作者
- 9a3dcafd7a83:容器ID
- lusifer/ubuntu:v2:指定要创建的目标镜像名
我们可以使用 docker images
命令来查看我们的新镜像 lusifer/ubuntu:v2:
lusifer@UbuntuBase:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lusifer/ubuntu v2 2642b4944b28 2 minutes ago 137MB
ubuntu 14.04 dea1945146b9 7 weeks ago 188MB
ubuntu 15.10 9b9cb95443b5 15 months ago 137MB
training/webapp latest 6fae60ef3446 2 years ago 349MB
使用我们的新镜像 lusifer/ubuntu 来启动一个容器:
lusifer@UbuntuBase:~$ docker run -it lusifer/ubuntu:v2 /bin/bash
root@060f7af5fbec:/#