批量删除正在运行的docker容器
docker rm -f $(docker ps -q)
#删除正在运行的容器 -q是容器ID
docker rm -f $(docker ps -q)
docker run -it centos /bin/bash
[root@c35acdee94f5 /]# pwd
/
[root@c35acdee94f5 /]# vim 1.txt
bash: vim: command not found
[root@c35acdee94f5 /]#
增强centos镜像
Dockerfile脚本内容
FROM centos
MAINTAINER zxl
ENV MYPATH /usr/local
WORKDIR $MYPATH
RUN yum -y install vim
RUN yum -y install net-tools
EXPOSE 80
CMD echo $MYPATH
CMD echo "success--------------------ok"
CMD /bin/bash
自定义Dockerfile脚本名称
docker build -f /workspace/docker/Dockerfile_mycentos -t mycentos:1.0 .
#构建日志分析
docker build -f /workspace/docker/Dockerfile_mycentos -t mycentos:1.0 .
Sending build context to Docker daemon 2.048kB
Step 1/10 : FROM centos
---> 831691599b88
Step 2/10 : MAINTAINER zxl
---> Running in e07788688d45
Removing intermediate container e07788688d45
---> a82dcc01fd28
Step 3/10 : ENV MYPATH /usr/local
---> Running in 41025cc720ea
Removing intermediate container 41025cc720ea
---> c8a228cfb683
Step 4/10 : WORKDIR $MYPATH
---> Running in d5886ae1db81
Removing intermediate container d5886ae1db81
---> a8a64debc724
Step 5/10 : RUN yum -y install vim
---> Running in 6aff19c80e35
Removing intermediate container 6aff19c80e35
---> 305e52dde1a4
Step 6/10 : RUN yum -y install net-tools
---> Running in 65cedbfcbd04
Removing intermediate container 65cedbfcbd04
---> 4205f2211f78
Step 7/10 : EXPOSE 80
---> Running in 4587d06aa791
Removing intermediate container 4587d06aa791
---> 33c9f36fedd5
Step 8/10 : CMD echo $MYPATH
---> Running in 67121426d7bd
Removing intermediate container 67121426d7bd
---> e9dfce53a5cf
Step 9/10 : CMD echo "success--------------------ok"
---> Running in f04f2b2cee9a
Removing intermediate container f04f2b2cee9a
---> af402f3387d7
Step 10/10 : CMD /bin/bash
---> Running in e81a287c288a
Removing intermediate container e81a287c288a
---> 512d695d8553
Successfully built 512d695d8553
Successfully tagged mycentos:1.0
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos 1.0 512d695d8553 About a minute ago 295MB
centos latest 831691599b88 6 weeks ago 215MB
基于自定义centos镜像运行容器
vim和ifconfig的命令都支持了。
docker run -it mycentos:1.0 /bin/bash
[root@03dbfdb30935 local]# pwd
/usr/local
[root@03dbfdb30935 local]# vim 1.txt
[root@03dbfdb30935 local]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 26 bytes 4558 (4.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@03dbfdb30935 local]#
docker history命令
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos 1.0 512d695d8553 12 minutes ago 295MB
centos latest 831691599b88 6 weeks ago 215MB
docker history 512d695d8553
IMAGE CREATED CREATED BY SIZE COMMENT
512d695d8553 12 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/bin… 0B
af402f3387d7 12 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo… 0B
e9dfce53a5cf 12 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo… 0B
33c9f36fedd5 12 minutes ago /bin/sh -c #(nop) EXPOSE 80 0B
4205f2211f78 12 minutes ago /bin/sh -c yum -y install net-tools 22.8MB
305e52dde1a4 13 minutes ago /bin/sh -c yum -y install vim 57.2MB
a8a64debc724 14 minutes ago /bin/sh -c #(nop) WORKDIR /usr/local 0B
c8a228cfb683 14 minutes ago /bin/sh -c #(nop) ENV MYPATH=/usr/local 0B
a82dcc01fd28 14 minutes ago /bin/sh -c #(nop) MAINTAINER zxl 0B
831691599b88 6 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 6 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 6 weeks ago /bin/sh -c #(nop) ADD file:84700c11fcc969ac0… 215MB