docker基础镜像alpine

alpine是面向安全应用的轻量级linux发行版本,拖下来看一下

[[email protected] ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
921b31ab772b: Pull complete
Digest: sha256:ca1c944a4f8486a153024d9965aafbe24f5723c1d5c02f4964c045a16d19dc54
Status: Downloaded newer image for alpine:latest
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 4d90542f0623 2 weeks ago 5.58MB
ubuntu 14.04 2c5e00d77a67 7 weeks ago 188MB
registry 2 f32a97de94e1 3 months ago 25.8MB
hello-world latest fce289e99eb9 6 months ago 1.84kB

这个镜像很小,只有几M

运行这个镜像,进去看看有哪些命令

[[email protected] ~]# docker run --rm -it alpine sh
/ # ls
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/ # cd bin/
/bin # ls
arch date fdflush kbd_mode mknod ping6 setpriv umount
ash dd fgrep kill mktemp pipe_progress setserial uname
base64 df fsync link more printenv sh usleep
bbconfig dmesg getopt linux32 mount ps sleep watch
busybox dnsdomainname grep linux64 mountpoint pwd stat zcat
cat dumpkmap gunzip ln mpstat reformime stty
chgrp echo gzip login mv rev su
chmod ed hostname ls netstat rm sync
chown egrep ionice lzop nice rmdir tar
conspy false iostat makemime pidof run-parts touch
cp fatattr ipcalc mkdir ping sed true
/bin # [[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ddca7736b585 alpine "sh" About a minute ago Up About a minute romantic_wiles
e37529b58640 registry:2 "/entrypoint.sh /etc…" About an hour ago Up About an hour 0.0.0.0:5000->5000/tcp registry
5fb08267227e ubuntu:14.04 "/bin/bash" 2 hours ago Up 2 hours ubuntu_4
be9d5c6f2a25 ubuntu:14.04 "/bin/bash" 3 hours ago Up 3 hours ubuntu_3
dca3d42e5e3e ubuntu:14.04 "/bin/bash" 3 hours ago Exited (0) 3 hours ago ubuntu_2
7103a04f97d3 ubuntu:14.04 "/bin/bash" 5 hours ago Up 5 hours ubuntu
[[email protected] ~]# 
删除容器试一下,报错没有退出,然后使用stop退出
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ddca7736b585 alpine "sh" About a minute ago Up About a minute romantic_wiles
e37529b58640 registry:2 "/entrypoint.sh /etc…" About an hour ago Up About an hour 0.0.0.0:5000->5000/tcp registry
5fb08267227e ubuntu:14.04 "/bin/bash" 3 hours ago Up 3 hours ubuntu_4
be9d5c6f2a25 ubuntu:14.04 "/bin/bash" 3 hours ago Up 3 hours ubuntu_3
dca3d42e5e3e ubuntu:14.04 "/bin/bash" 3 hours ago Exited (0) 3 hours ago ubuntu_2
7103a04f97d3 ubuntu:14.04 "/bin/bash" 5 hours ago Up 5 hours ubuntu
[[email protected] ~]# docker rm ddca
Error response from daemon: You cannot remove a running container ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446. Stop the container before attempting removal or force remove
[[email protected] ~]# docker stop ddca
ddca

可以发现,停止容器后,容器就被删除了,这是因为我们创建的时候指定了-rm选项,所以退出就删除了,这个过程,可以结合events来观察

2019-07-05T00:48:43.917483851+08:00 image pull alpine:latest (name=alpine)
2019-07-05T00:49:33.746443011+08:00 container create ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14 name=romantic_wiles)
2019-07-05T00:49:33.748899933+08:00 container attach ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14 name=romantic_wiles)
2019-07-05T00:49:33.789490362+08:00 network connect 05475ea368337254dea611bfff0a86005befb5ea3da6e3bb6b7b3d40bbe4e37736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446, name=bridge, type=bridge)
2019-07-05T00:49:34.479785409+08:00 container start ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a144name=romantic_wiles)
2019-07-05T00:49:34.485932045+08:00 container resize ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14age=alpine, name=romantic_wiles, width=132)
##新建容器,并启动
2019-07-05T00:51:25.794561487+08:00 container kill ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446 (image=alpine, name=romantic_wiles, signal=15)
2019-07-05T00:51:35.841292955+08:00 container kill ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446 (image=alpine, name=romantic_wiles, signal=9)
2019-07-05T00:51:36.322103770+08:00 container die ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446 (exitCode=137, image=alpine, name=romantic_wiles)
2019-07-05T00:51:36.408362193+08:00 network disconnect 05475ea368337254dea611bfff0a86005befb5ea3da6e3bb6b7b3d40bbe4e33e (container=ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446, name=bridge, type=bridge)
2019-07-05T00:51:36.436651884+08:00 container stop ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446 (image=alpine, name=romantic_wiles)
2019-07-05T00:51:36.438911920+08:00 container destroy ddca7736b58589d96d2af216edf9488be1baab2ab5a3d7a122f871f128a14446 (image=alpine, name=romantic_wiles)
##停止容器,可以看到使用的是kill,因为加了-rm选项,所以退出就删除了这个容器
此条目发表在Docker分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注