管理容器常用命令

IT
IT
IT
285
文章
1
评论
2020年5月15日13:39:39 评论 78 3469字阅读11分33秒

管理容器常用命令

 

当前运行的容器

[root@VM_0_8_centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15a6a1f74ffe nginx "nginx -g 'daemon of…" 11 minutes ago Up 11 minutes 80/tcp web04
19fc30aa95c2 nginx "nginx -g 'daemon of…" 19 minutes ago Up 19 minutes 80/tcp web03
7ddab59d9cd2 nginx "nginx -g 'daemon of…" 20 hours ago Up 20 hours 80/tcp pensive_meninsky

列出最新创建的容器

[root@VM_0_8_centos ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15a6a1f74ffe nginx "nginx -g 'daemon of…" 12 minutes ago Up 12 minutes 80/tcp web04

列出所有的容器

[root@VM_0_8_centos ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15a6a1f74ffe nginx "nginx -g 'daemon of…" 14 minutes ago Up 14 minutes 80/tcp web04
19fc30aa95c2 nginx "nginx -g 'daemon of…" 22 minutes ago Up 22 minutes 80/tcp web03
7ddab59d9cd2 nginx "nginx -g 'daemon of…" 20 hours ago Up 20 hours 80/tcp pensive_meninsky
df53608eeaa9 hello-world "/hello" 23 hours ago Exited (0) 23 hours ago quizzical_rosalind

查看容器的详细信息

[root@VM_0_8_centos ~]# docker inspect 15a6a1f74ffe

进入一个容器中

[root@VM_0_8_centos ~]# docker exec -it web04 bash
root@15a6a1f74ffe:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

创建一个新镜像来自一个容器

[root@VM_0_8_centos ~]# docker exec -it web04 bash
root@15a6a1f74ffe:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@15a6a1f74ffe:/# touch 1.txt
root@15a6a1f74ffe:/# exit
exit
[root@VM_0_8_centos ~]# docker commit web04 nginx:web04
sha256:bec26c1b1f71d49676f6c8b60778f34d2b84ad1fdd3957517bea31c495211c4d
[root@VM_0_8_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx web04 bec26c1b1f71 4 seconds ago 126MB
nginx latest 5a3221f0137b 2 weeks ago 126MB
hello-world latest fce289e99eb9 8 months ago 1.84kB

查看分层

[root@VM_0_8_centos ~]# docker history nginx
IMAGE CREATED CREATED BY SIZE COMMENT
5a3221f0137b 2 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B 
<missing> 2 weeks ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B 
<missing> 2 weeks ago /bin/sh -c #(nop) EXPOSE 80 0B 
<missing> 2 weeks ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B 
<missing> 2 weeks ago /bin/sh -c set -x && addgroup --system -… 56.8MB 
<missing> 2 weeks ago /bin/sh -c #(nop) ENV PKG_RELEASE=1~buster 0B 
<missing> 2 weeks ago /bin/sh -c #(nop) ENV NJS_VERSION=0.3.5 0B 
<missing> 2 weeks ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.17.3 0B 
<missing> 3 weeks ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B 
<missing> 3 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B 
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:330bfb91168adb4a9… 69.2MB

拷贝文件到容器里

[root@VM_0_8_centos ~]# ll
total 0
[root@VM_0_8_centos ~]# touch 1.txt
[root@VM_0_8_centos ~]# docker cp 1.txt web04:/

[root@VM_0_8_centos ~]# docker exec -it web04 bash
root@15a6a1f74ffe:/# ls
1.txt bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@15a6a1f74ffe:/#

查看容器日志

[root@VM_0_8_centos ~]# docker logs web04

列出或指定端口映射

[root@VM_0_8_centos ~]# docker port 15a6a1f74ffe

显示一个容器运行的进程

[root@VM_0_8_centos ~]# docker top 15a6a1f74ffe 
UID PID PPID C STIME TTY TIME CMD
root 22264 22247 0 19:41 ? 00:00:00 nginx: master process nginx -g daemon off;
101 22296 22264 0 19:41 ? 00:00:00 nginx: worker process

查看当前限制的镜像信息

[root@VM_0_8_centos ~]# docker stats web03 
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
19fc30aa95c2 web03 0.00% 1.387MiB / 500MiB 0.28% 648B / 0B 1.7MB / 0B 2
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS

上面是动态显示,现在静态显示。

[root@VM_0_8_centos ~]# docker stats --no-stream web03
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
19fc30aa95c2 web03 0.00% 1.387MiB / 500MiB 0.28% 648B / 0B 1.7MB / 0B 2

删除容器(删除和强制删除)

[root@VM_0_8_centos ~]# docker rm 15a6a1f74ffe
Error response from daemon: You cannot remove a running container 15a6a1f74ffeb58a5ef78de25970a3314f578d8341abe8937079f416cd716e3d. Stop the container before attempting removal or force remove
[root@VM_0_8_centos ~]# docker rm -f 15a6a1f74ffe
15a6a1f74ffe
继续阅读
  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
IT
  • 本文由 发表于 2020年5月15日13:39:39
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Centos8.1安装docker Docker

Centos8.1安装docker

yum方式安装 安装依赖 # yum install -y yum-utils device-mapper-persistent-data lvm2 添加仓库 # yum-config-manager...
docker安装mysql8.0 Docker

docker安装mysql8.0

创建存储目录 # mkdir -p /opt/data/mysql/data /opt/data/mysql/conf 基本使用 创建区分大小写文件 # cd /opt/data/mysql/conf...
二进制部署docker Docker

二进制部署docker

安装Docker 二进制包下载地址:https://download.docker.com/linux/static/stable/ 到对应平台的目录下载所需版本的Docker二进制包,并上传到Nod...