Docker常用命令(一)
程序员文章站
2022-03-12 18:28:46
...
具体docker的优势我就不说了,下面就使用docker的一些常用命令具体详细说下:
1、docker的启动、停止、重启
2、docker创建一个容器
[[email protected] ~]# docker run -it -v /docker_test:/yufei --name yufei_6 centos
[[email protected] /]#
-i:允许我们对容器内的 (STDIN) 进行交互
-t:在新容器内指定一个伪终端或终端
-v:是挂在宿机目录, /docker_test是宿机目录,/yufei是当前docker容器的目录,宿机目录必须是绝对的。
--name:是给容器起一个名字,可省略,省略的话docker会随机产生一个名字
3、docker查看启动的容器列表
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
724e7701f0d4 centos "/bin/bash" 4 minutes ago Up 4 minutes yufei_6
f9097691663e centos "/bin/bash" 5 minutes ago Up 5 minutes yufei_5
[[email protected] ~]#
4、查看docker创建的所有容器
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
724e7701f0d4 centos "/bin/bash" 5 minutes ago Up 5 minutes yufei_6
f9097691663e centos "/bin/bash" 6 minutes ago Up 6 minutes yufei_5
e59a540fb979 centos "/bin/base" 6 minutes ago Created yufei_4
ff49dfedea4f centos "/bin/bash" 2 hours ago Exited (137) 10 minutes ago yufei_03
d2cc70abb5a5 centos "/bin/bash" 2 hours ago Exited (127) 2 hours ago yufei_02
2d48fc5b7c17 centos "/bin/bash" 2 hours ago Exited (127) 2 hours ago yufei_01
[[email protected] ~]#
5、启动、停止、重启某个docker 容器
[[email protected] ~]# docker start yufei_01
yufei_01
[[email protected] ~]# docker stop yufei_01
yufei_01
[[email protected] ~]# docker restart yufei_01
yufei_01
[[email protected] ~]#
6、查看指定容器的日志记录
<span style="color:#333333;">[[email protected] ~]# docker logs -f yufei_01
</span><span style="background-color:rgb(51,204,255);"><span style="color:#ff0000;">[[email protected] /]# ls
anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[[email protected] /]# exit
exit
[[email protected] /]# ls
anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[[email protected] /]#
[[email protected] /]#
[[email protected] /]#
[[email protected] /]#
[[email protected] /]#
[[email protected] /]#
[[email protected] /]#
[[email protected] /]# cd /
[[email protected] /]# ls
anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[[email protected] /]# mkdir yufei
[[email protected] /]# ls
anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var yufei
[[email protected] /]# cd yufei
[[email protected] yufei]# ls
yufei
[[email protected] yufei]# cd yufei
[[email protected] yufei]# ls
application
[[email protected] yufei]# cd ../../
[[email protected] /]# rm -rf yufei
[[email protected] /]# eixt
bash: eixt: command not found
[[email protected] /]# exit
exit</span></span><span style="color:#333333;">
[[email protected] /]# </span>
7、删除某个容器,若正在运行,需要先停止
[[email protected] ~]# docker rm yufei_01
Error response from daemon: You cannot remove a running container 2d48fc5b7c17b01e6247cbc012013306faf1e54f24651d5e16d6db4e15f92d33. Stop the container before attempting removal or use -f
[[email protected] ~]# docker stop yufei_01
yufei_01
[[email protected] ~]# docker rm yufei_01
yufei_01
[[email protected] ~]#
8、删除所有容器
[[email protected] ~]# docker rm $(docker ps -a -q)
Error response from daemon: You cannot remove a running container 724e7701f0d4a830167e21f75b470235a0e408fd6cc2913403426e96f69cba11. Stop the container before attempting removal or use -f
Error response from daemon: You cannot remove a running container f9097691663ee36f9d2ee56afbdcca0eeb8b63e5590ddf18c0c42954c93b9f06. Stop the container before attempting removal or use -f
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# docker stop yufei_6
yufei_6
[[email protected] ~]# docker stop yufei_5
yufei_5
[[email protected] ~]# docker rm $(docker ps -a -q)
724e7701f0d4
f9097691663e
[[email protected] ~]#
9、查看所有镜像列表
[[email protected] springboot]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
my-images latest dd3e12316fc6 5 hours ago 657.3 MB
registry.cn-hangzhou.aliyuncs.com/jack_wx/redis 3.0 40b1f67fd3d4 2 weeks ago 83.38 MB
redis latest 40b1f67fd3d4 2 weeks ago 83.38 MB
centos latest 88ec626ba223 8 weeks ago 199.7 MB
java latest d11c3799fa6a 18 months ago 643.1 MB
[[email protected] springboot]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
my-images latest dd3e12316fc6 6 hours ago 657.3 MB
redis latest 40b1f67fd3d4 2 weeks ago 83.38 MB
registry.cn-hangzhou.aliyuncs.com/jack_wx/redis 3.0 40b1f67fd3d4 2 weeks ago 83.38 MB
centos latest 88ec626ba223 8 weeks ago 199.7 MB
java latest d11c3799fa6a 18 months ago 643.1 MB
10、删除某个镜像
[[email protected] springboot]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
my-images latest dd3e12316fc6 6 hours ago 657.3 MB
registry.cn-hangzhou.aliyuncs.com/jack_wx/redis 3.0 40b1f67fd3d4 2 weeks ago 83.38 MB
redis latest 40b1f67fd3d4 2 weeks ago 83.38 MB
centos latest 88ec626ba223 8 weeks ago 199.7 MB
java latest d11c3799fa6a 18 months ago 643.1 MB
[[email protected] springboot]# docker rmi registry.cn-hangzhou.aliyuncs.com/jack_wx/redis:3.0
Untagged: registry.cn-hangzhou.aliyuncs.com/jack_wx/redis:3.0
[[email protected] springboot]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
my-images latest dd3e12316fc6 6 hours ago 657.3 MB
redis latest 40b1f67fd3d4 2 weeks ago 83.38 MB
centos latest 88ec626ba223 8 weeks ago 199.7 MB
java latest d11c3799fa6a 18 months ago 643.1 MB
[[email protected] springboot]#
11、修改某个镜像的名称
[[email protected] springboot]# docker tag dd3e12316fc6 my-images-new
[[email protected] springboot]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
my-images-new latest dd3e12316fc6 6 hours ago 657.3 MB
my-images latest dd3e12316fc6 6 hours ago 657.3 MB
redis latest 40b1f67fd3d4 2 weeks ago 83.38 MB
centos latest 88ec626ba223 8 weeks ago 199.7 MB
java latest d11c3799fa6a 18 months ago 643.1 MB
[[email protected] springboot]#
上一篇: Python_实用入门篇_13