Docker容器的基本管理 | IT运维网
  • 欢迎访问本网站;本站QQ交流群:654792529;如果您觉得本站非常有看点,那么赶紧使用Ctrl+D收藏吧!
  • 本站为个人技术性博客网站,上面会更新一些系统、网络、云计算和监控等相关运维的技术性文章,供大家参考、学习和一起交流。

Docker容器的基本管理

Docker yvan 1年前 (2018-08-20) 735次浏览 已收录 0个评论 扫描二维码

显示所有容器列表(包括启动状态的和未启动状态的;等同于docker ps -a):docker container ls -a

[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS                       PORTS                NAMES
10c99f08efc8        thehunt33r/docker-brimir   "/bin/sh -c '/etc/in…"   2 minutes ago       Exited (137) 4 seconds ago                        hardcore_hugle
5f6083a38441        nginx                      "nginx -g 'daemon of…"   4 minutes ago       Up 4 minutes                 0.0.0.0:80->80/tcp   youthful_fer

不加参数(-a)为只显示启动状态的容器列表

创建Docker容器(等同于docker craete):docker container create nginx        #此方式仅是创建容器而不启动容器

[root@localhost ~]# docker image ls
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
nginx                      latest              42b4762643dc        7 days ago          109MB
thehunt33r/docker-brimir   latest              b7bf3e5cd2cf        2 years ago         1.19GB
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@localhost ~]# docker container create nginx
7fc9e61ed8d40f27989caa1265465170d21de99b4ab5ad080ce520a4059e3dce
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   4 seconds ago       Created                                 gallant_antonelli

启动指定Docker容器(等同于docker start):docker container start 容器名/ID

[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   2 minutes ago       Created                                 gallant_antonelli
[root@localhost ~]# docker container start 7fc9e61ed8d4
7fc9e61ed8d4
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   5 minutes ago       Up 3 seconds        80/tcp              gallant_antonelli

停止指定Docker容器(等同于docker stop):docker container stop 容器名/ID

[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   8 minutes ago       Up 3 seconds        80/tcp              gallant_antonelli
[root@localhost ~]# docker container stop gallant_antonelli
gallant_antonelli
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   8 minutes ago       Exited (0) 3 seconds ago                       gallant_antonelli

重启指定Docker容器(等同于docker restart):docker container restart 容器名/ID

[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   8 minutes ago       Exited (0) 3 seconds ago                       gallant_antonelli
[root@localhost ~]# docker container restart 7fc9e61ed8d4
7fc9e61ed8d4
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   10 minutes ago      Up 2 seconds        80/tcp              gallant_antonelli

杀死指定Docker容器(等同于docker kill):docker container kill 容器名/ID        #当容器处于异常状态不能正常停止或重启时可用此命令结束容器

[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   13 minutes ago      Up 3 minutes        80/tcp              gallant_antonelli
[root@localhost ~]# docker container kill 7fc9e61ed8d4
7fc9e61ed8d4
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   14 minutes ago      Exited (137) 3 seconds ago                       gallant_antonelli

删除非启动状态的容器(等同于docker rm):docker container rm 容器名/ID

[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   13 minutes ago      Up 3 minutes        80/tcp              gallant_antonelli
[root@localhost ~]# docker container kill 7fc9e61ed8d4
7fc9e61ed8d4
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
7fc9e61ed8d4        nginx               "nginx -g 'daemon of…"   14 minutes ago      Exited (137) 3 seconds ago                       gallant_antonelli
[root@localhost ~]# docker container rm 7fc9e61ed8d4
7fc9e61ed8d4
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

强制删除容器(包括启动状态的和未启动状态的):docker container rm -f 容器名/ID

[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
951b0a99aa0f        nginx               "nginx -g 'daemon of…"   5 seconds ago       Up 4 seconds        80/tcp              gallant_volhard
[root@localhost ~]# docker container rm -f 951b0a99aa0f
951b0a99aa0f
[root@localhost ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

IT运维网 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Docker容器的基本管理
喜欢 (1)
[yvan.lu@ityww.cn]
分享 (0)
yvan
关于作者:
聪明来自勤奋、知识在于积累、好记性不如烂键盘!

您必须 登录 才能发表评论!