Docker入门二

Posted sunyujun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker入门二相关的知识,希望对你有一定的参考价值。

容器管理

技术分享图片

1.docker create创建一个容器,但容器并没启动,就和我们创建虚拟机一样,创建了虚拟机后没启动

[[email protected] ~]# docker create -it centos6 bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
558e31f7b0fb941ca4ee8c1c2b42553b06ac79c0613984b7ad8b9b4ba97f61fd
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
558e31f7b0fb        centos6             "bash"              9 seconds ago       Created                                 hopeful_murdock
94b9eab05296        centos6             "bash"              About an hour ago   Up About an hour                        elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected] ~]# 

2.启动容器

[[email protected] ~]# docker start 558e31f7b0fb
558e31f7b0fb
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
558e31f7b0fb        centos6             "bash"              2 minutes ago       Up 8 seconds                            hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up About an hour                        elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected] ~]# 

3.不加-d运行容器

[[email protected] ~]# docker run -it centos bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
[[email protected] /]# ls
bin  etc   lib    media  opt   root  sbin  sys  usr
dev  home  lib64  mnt    proc  run   srv   tmp  var

4.我们用ctrl+d退出,然后查看容器发现没有f4eba170402c,因为我们退出了之前的bash,这是因为我们退出了没有加-d,加上-a参数查看状态为Exited,

[[email protected] /]# exit
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
558e31f7b0fb        centos6             "bash"              10 minutes ago      Up 7 minutes                            hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                              elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected] ~]# 
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
f4eba170402c        centos              "bash"              3 minutes ago       Exited (0) 2 minutes ago                       cocky_bell
558e31f7b0fb        centos6             "bash"              12 minutes ago      Up 9 minutes                                   hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                                     elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                                      distracted_mahavira
[[email protected] ~]# 

5.给容器起个名字

[[email protected] ~]# docker run -itd --name centos6_1 centos6 bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
5e32153dbbd6dea32b62291f9aa484b1d82c84d5edf9899ab72a8335f61e16ac
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5e32153dbbd6        centos6             "bash"              15 seconds ago      Up 11 seconds                           centos6_1
558e31f7b0fb        centos6             "bash"              17 minutes ago      Up 14 minutes                           hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                              elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected] ~]# 

6.可以直接用名字进入容器

[[email protected] ~]# docker exec -it centos6_1 bash
[[email protected] /]# 

7.容器执行完直接删除、命令执行完容器就退出,执行完不留任何痕迹。

[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5e32153dbbd6        centos6             "bash"              5 minutes ago       Up 5 minutes                            centos6_1
558e31f7b0fb        centos6             "bash"              22 minutes ago      Up 19 minutes                           hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                              elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected] ~]# docker run --rm -it centos bash -c "sleep 10"
WARNING: IPv4 forwarding is disabled. Networking will not work.
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
5e32153dbbd6        centos6             "bash"              7 minutes ago       Up 6 minutes                                    centos6_1
f4eba170402c        centos              "bash"              15 minutes ago      Exited (0) 13 minutes ago                       cocky_bell
558e31f7b0fb        centos6             "bash"              23 minutes ago      Up 21 minutes                                   hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                                      elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                                       distracted_mahavira
[[email protected] ~]# 

技术分享图片

1.docker logs查看容器运行历史信息

[[email protected] ~]# docker run -itd centos bash -c "echo 123"
WARNING: IPv4 forwarding is disabled. Networking will not work.
59e0b06bcfb4e407ba29719e0bd805c8f52948429ecfbf94c8616ea5090dcd37
[[email protected] ~]# docker logs 59e0b0
123
[[email protected] ~]# 

2.删除容器 rm,删除一个启动的容器加-f参数

[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
59e0b06bcfb4        centos              "bash -c ‘echo 123‘"   2 minutes ago       Exited (0) 2 minutes ago                        xenodochial_hoover
5e32153dbbd6        centos6             "bash"                 18 minutes ago      Up 18 minutes                                   centos6_1
f4eba170402c        centos              "bash"                 26 minutes ago      Exited (0) 24 minutes ago                       cocky_bell
558e31f7b0fb        centos6             "bash"                 34 minutes ago      Up 32 minutes                                   hopeful_murdock
94b9eab05296        centos6             "bash"                 2 hours ago         Up 2 hours                                      elegant_minsky
815adfd9da61        centos              "/bin/bash"            3 days ago          Up 3 days                                       distracted_mahavira
[[email protected] ~]# docker rm 59e0b06bcfb4
59e0b06bcfb4
[[email protected] ~]# docker rm f4eba170402c
f4eba170402c
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5e32153dbbd6        centos6             "bash"              20 minutes ago      Up 20 minutes                           centos6_1
558e31f7b0fb        centos6             "bash"              37 minutes ago      Up 34 minutes                           hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                              elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected] ~]#  
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5e32153dbbd6        centos6             "bash"              21 minutes ago      Up 21 minutes                           centos6_1
558e31f7b0fb        centos6             "bash"              38 minutes ago      Up 35 minutes                           hopeful_murdock
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                              elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected]os-02 ~]# docker rm 558e31f7b0fb
Error response from daemon: You cannot remove a running container 558e31f7b0fb941ca4ee8c1c2b42553b06ac79c0613984b7ad8b9b4ba97f61fd. Stop the container before attempting removal or 
force remove [[email protected] ~]# docker rm -f 558e31f7b0fb 558e31f7b0fb [[email protected] ~]#
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5e32153dbbd6        centos6             "bash"              22 minutes ago      Up 22 minutes                           centos6_1
94b9eab05296        centos6             "bash"              2 hours ago         Up 2 hours                              elegant_minsky
815adfd9da61        centos              "/bin/bash"         3 days ago          Up 3 days                               distracted_mahavira
[[email protected] ~]# 

仓库管理

技术分享图片

1.用registry镜像搭建私有仓库

  

  

  

  

  

  

  

  

  


以上是关于Docker入门二的主要内容,如果未能解决你的问题,请参考以下文章

OpenGL基础学习之二代码基本结构

为什么二代测序的原始数据中会出现Read重复现象?

三代测序入门

二代身份证号码编码规则

染色体基因芯片分析和第二代测序应用的区别

反射机制入门