码迷,mamicode.com
首页 > 其他好文 > 详细

Docker 常用命令2

时间:2019-01-21 19:24:33      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:pid   rgs   lamp   acl   ted   containe   等价   min   arc   

 #只显示当前本地镜像的ID 

[root@weblamp ~]# docker images -q
9f5834b25059

#显示全部的本地镜像的ID 
[root@weblamp ~]# docker images -qa
9f5834b25059
65b27d3bd74d

#显示镜像的摘要信息
[root@weblamp ~]# docker images --digests 
REPOSITORY TAG DIGEST IMAGE ID CREATED VIRTUAL SIZE
hello-world latest <none> 9f5834b25059 4 days ago 1.84 kB

 #显示镜像的完整信息
[root@weblamp ~]# docker images --no-trunc
REPOSITORY TAG IMAGE ID CREATED
VIRTUAL SIZE
hello-world latest 9f5834b25059239faef06a9ba681db7b7c572fc0d87d2b140b10e90e50902b53 4 days ago
1.84 kB
#列出收藏数大于30的镜像

[root@weblamp ~]# docker search -s 30 tomcat 
NAME DESCRIPTION STARS OFFICIAL AUTOMATEDAUTOMATED
tomcat Apache Tomcat is an open source implementa... 2246 [OK]
tomee Apache TomEE is an all-Apache Java EE cert... 59 [OK]
dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 51 [OK]
davidcaste/alpine-tomcat Apache Tomcat 7/8 using Oracle Java 7/8 wi... 31 [OK]

#下载镜像
[root@weblamp ~]# docker pull tomcat

#等价于 docker pull tomcat:latest
#删除镜像
[root@weblamp ~]# docker rmi -f hello-world
Untagged: hello-world:latest
Deleted: 9f5834b25059239faef06a9ba681db7b7c572fc0d87d2b140b10e90e50902b53
Deleted: 65b27d3bd74d2cf4ea3aa9e250be6c632f0a347e8abd5485345c55fa6eed0258
[root@weblamp ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tomcat latest 0260919306ba 6 days ago 462.4 MB

#删除所有的镜像(i:表示镜像)

[root@weblamp ~]# docker rmi -f $(docker images -qa) 

#运行容器
[root@weblamp ~]# docker run -it centos
[root@d1e49e5ec93d /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 09:00 ? 00:00:00 /bin/bash
root 15 1 0 09:00 ? 00:00:00 ps -ef


#查看正在运行的容器
[root@weblamp ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
d1e49e5ec93d centos "/bin/bash" About a minute ago Up About a minute
naughty_fermi

#退出并关闭容器
[root@b8b5c1a57b2c /]# exit (#容器停止并退出,ctrl+P+Q 容器不停止的情况下退出容器)

#列出上一次运行的容器(不是数字‘1’)

[root@weblamp ~]# docker ps -l 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
b8b5c1a57b2c centos "/bin/bash" 6 minutes ago Exited (0) 21 seconds ago
compassionate_wilson

 #列出上3次运行的容器

[root@weblamp ~]# docker ps -n 3
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
b8b5c1a57b2c centos "/bin/bash" 8 minutes ago Exited (0) 2 minutes ago
compassionate_wilson
c668511d9dc3 hello-world "/hello" 30 hours ago Exited (0) 30 hours ago
angry_curie

#历史运行的容器

[root@weblamp ~]# docker ps -a 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
b8b5c1a57b2c centos "/bin/bash" 6 minutes ago Exited (0) 28 seconds ago
compassionate_wilson
c668511d9dc3 hello-world "/hello" 30 hours ago Exited (0) 30 hours ago
angry_curie

#运行一个centos容器,指定别名为mycentos

[root@weblamp ~]# docker run -it --name mycentos ab9a80ab07d0 
[root@5783a20d79c9 /]#

[root@weblamp ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
5783a20d79c9 ab9a80ab07d0 "/bin/bash" 18 seconds ago Up 17 seconds
mycentos

#查看运行过的容器,并启动已经关闭的容器
[root@weblamp ~]# docker ps -n 3
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
5783a20d79c9 ab9a80ab07d0 "/bin/bash" 8 minutes ago Up 8 minutes
mycentos
b8b5c1a57b2c centos "/bin/bash" 21 minutes ago Exited (0) 15 minutes ago
compassionate_wilson
c668511d9dc3 hello-world "/hello" 30 hours ago Exited (0) 30 hours ago
angry_curie
[root@weblamp ~]# docker start b8b5c1a57b2c
b8b5c1a57b2c
[root@weblamp ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
5783a20d79c9 ab9a80ab07d0 "/bin/bash" 9 minutes ago Up 9 minutes
mycentos
b8b5c1a57b2c centos "/bin/bash" 22 minutes ago Up 6 seconds
compassionate_wilson

#停止容器
[root@weblamp ~]# docker stop ab9a80ab07d0 

#强制停止容器

[root@weblamp ~]# docker kill ab9a80ab07d0 

 #删除已经停止的容器

[root@weblamp ~]# docker rm ab9a80ab07d0

#强制删除容器,不管是否停止

[root@weblamp ~]# docker rm -f ab9a80ab07d0 

#强制删除所有的容器 docker ps -qa|xargs docker rm
[root@weblamp ~]# docker rm -f $(docker ps -qa) 

 #后台启动一个centos容器,启动后就退出了

[root@weblamp ~]# docker run -d centos
566663e3632122a7b10c5ea76e116ffc12e9173f6075f7c25d76721a026955d2


[root@weblamp ~]# docker run -d centos /bin/sh -c "while true;do echo hello zzyy;sleep 2;done"
c0f8dd6e7e7806d16eee45abbc3481afd2c2c64450f76b9dfefca734a0f71f76
[root@weblamp ~]#

[root@weblamp ~]# docker logs c0f8dd6e7e78
hello zzyy
hello zzyy
hello zzyy
hello zzyy
hello zzyy
hello zzyy

[root@weblamp ~]# docker logs -t -f --tail 5 c0f8dd6e7e78
2019-01-05T09:32:47.259055965Z hello zzyy
2019-01-05T09:32:49.262340607Z hello zzyy
2019-01-05T09:33:07.290292608Z hello zzyy
2019-01-05T09:33:09.293592246Z hello zzyy
2019-01-05T09:33:11.304916080Z hello zzyy
2019-01-05T09:33:13.308580989Z hello zzyy
2019-01-05T09:33:15.310645986Z hello zzyy
2019-01-05T09:33:17.312546777Z hello zzyy
2019-01-05T09:33:19.314682982Z hello zzyy

Docker 常用命令2

标签:pid   rgs   lamp   acl   ted   containe   等价   min   arc   

原文地址:https://www.cnblogs.com/ahtornado/p/10299918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!