• Docker常用命令


    1.查看Docker版本

    [root@localhost ~]# docker version
    Client version: 1.7.1
    Client API version: 1.19
    Go version (client): go1.4.2
    Git commit (client): 786b29d/1.7.1
    OS/Arch (client): linux/amd64
    Server version: 1.7.1
    Server API version: 1.19
    Go version (server): go1.4.2
    Git commit (server): 786b29d/1.7.1
    OS/Arch (server): linux/amd64
    

    2.搜索可用的Docker镜像

    [root@localhost ~]# docker search centos
    NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    centos                                      The official build of CentOS.                   1314      [OK]       
    ansible/centos7-ansible                     Ansible on Centos7                              55                   [OK]
    jdeathe/centos-ssh-apache-php               CentOS-6 6.6 x86_64 / Apache / PHP / PHP m...   11                   [OK]
    blalor/centos                               Bare-bones base CentOS 6.5 image                9                    [OK]
    torusware/speedus-centos                    Always updated official CentOS docker imag...   6                    [OK]
    openshift/wildfly-8-centos                  DEPRECATED - see openshift/wildfly-81-centos7   6                    [OK]
    jdeathe/centos-ssh                          CentOS-6 6.6 x86_64 / EPEL/IUS Repos / Ope...   6                    [OK]
    million12/centos-supervisor                 Base CentOS-7 with supervisord launcher, h...   6                    [OK]
    nimmis/java-centos                          This is docker images of CentOS 7 with dif...   5                    [OK]
    nathonfowlie/centos-jre                     Latest CentOS image with the JRE pre-insta...   2                    [OK]
    jdeathe/centos-ssh-mysql                    CentOS-6 6.6 x86_64 / MySQL.                    2                    [OK]
    feduxorg/centos                                                                             1                    [OK]
    layerworx/centos                            CentOS container with etcd, etcdctl, confd...   1                    [OK]
    centos/mariadb55-centos7                                                                    1                    [OK]
    nathonfowlie/centos-jira                    JIRA running on the latest version of CentOS    1                    [OK]
    lighthopper/orientdb-centos                 A Dockerfile for creating an OrientDB imag...   1                    [OK]
    yajo/centos-epel                            CentOS with EPEL and fully updated              1                    [OK]
    lighthopper/openjdk-centos                  A Dockerfile for creating an OpenJDK image...   0                    [OK]
    jasonish/centos-suricata                    Suricata base image based on CentOS 7.          0                    [OK]
    insaneworks/centos                          CentOS 6.5 x86_64 + @update                     0                    [OK]
    blacklabelops/centos                        Blacklabelops Centos 7.1.503 base image wi...   0                    [OK]
    pdericson/centos                            Docker image for CentOS                         0                    [OK]
    radiantbluetechnologies/rialtobase-centos   rialtobase-centos                               0                    [OK]
    feduxorg/centos-rack                        Centos to run rack applications like Ruby ...   0                    [OK]
    jsmigel/centos-epel                         Docker base image of CentOS w/ EPEL installe
    

    仓库名/镜像                                                    介绍                                                          热度          是否官方提供  自动创建

    3.下载docker镜像

    [root@localhost ~]# docker pull ansible/centos7-ansible
    latest: Pulling from ansible/centos7-ansible
    8eeda73d87df: Pull complete 
    8f137f6d38c1: Pull complete 
    1a50897796a7: Pull complete 
    88555f28b7e7: Pull complete 
    4bbeb012a7d7: Pull complete 
    3f5df08205ea: Pull complete 
    9c7646887b8a: Pull complete 
    719604feb5a5: Pull complete 
    25a4ad4731e3: Pull complete 
    f240103e8c02: Pull complete 
    231b24a3be84: Pull complete 
    231b24a3be84: Pulling fs layer 
    47d44cb6f252: Already exists 
    f6f39725d938: Already exists 
    f9a8cbc8dd13: Already exists 
    f37e6a610a37: Already exists 
    Digest: sha256:4c949411e556a423d6e95affda4908d4d295f3a5d59443925e9db30c400473ac
    Status: Downloaded newer image for ansible/centos7-ansible:latest
    

    4.查看所有Docker镜像

    [root@localhost ~]# docker images
    REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    ansible/centos7-ansible   latest              231b24a3be84        11 hours ago        400.5 MB
    centos                    latest              0f73ae75014f        2 days ago          172.3 MB
    ubuntu                    latest              91e54dfb1179        2 weeks ago         188.3 MB
    

    5.启动、关闭容器

    [root@localhost ~]# docker start bea707b2a8fe
    bea707b2a8fe
    [root@localhost ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    bea707b2a8fe        centos:latest       "/bin/bash"         About an hour ago   Up 7 seconds                            gloomy_lovelace     
    
    [root@localhost ~]# docker stop bea707b2a8fe
    bea707b2a8fe
    [root@localhost ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    

    docker ps是查看正在运行中的容器

    6.docker镜像的导入

    cat   centos.tar | docker import  -  centos6 
    

    7.docker镜像的导出

    [root@localhost ~]# docker export b277a4166ab8 >centosipshow
    [root@localhost ~]# find / -name centosipshow
    /root/centosipshow

    8.运行centos容器输出“hello,world”

    [root@localhost ~]# docker images | grep centos
    ansible/centos7-ansible   latest              231b24a3be84        11 hours ago        400.5 MB
    centos                    latest              0f73ae75014f        2 days ago          172.3 MB
    [root@localhost ~]# docker run centos:latest echo "hello,world"
    hello,world
    

    9.查看centos latest的版本信息和网络信息

    [root@localhost ~]# docker run centos:latest cat /etc/redhat-release 
    CentOS Linux release 7.1.1503 (Core) 
    [root@localhost ~]# docker run centos:latest ip addr show
    22: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
        link/ether 02:42:ac:11:00:07 brd ff:ff:ff:ff:ff:ff
        inet 172.17.0.7/16 scope global eth0
        inet6 fe80::42:acff:fe11:7/64 scope link tentative 
           valid_lft forever preferred_lft forever
    24: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    

    10.在容器里启动一个交互式容器

    [root@localhost ~]# docker run -i -t centos:latest /bin/bash
    [root@bea707b2a8fe /]# cat /etc/redhat-release 
    CentOS Linux release 7.1.1503 (Core) 
    

    -t 表示打开一个终端的意思,-i表示可以交互输入

    11.创建一个后台型容器

    [root@localhost ~]# docker run -d centos:latest /bin/bash -c "while true;do echo hello;sleep 1;done "
    90eab2a7e8ececb30882627363407b471a4f0119f8771091bf45023d09bff10d
    [root@localhost ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
    90eab2a7e8ec        centos:latest       "/bin/bash -c 'while   7 seconds ago       Up 3 seconds                            naughty_pike        
    2b3347837a45        ubuntu              "/bin/bash -c 'while   About an hour ago   Up About an hour                        modest_brattain     
    [root@localhost ~]# docker attach 90eab2a7e8ec
    hello
    hello
    hello
    

      

    12.查看最后一个容器的状态

    [root@localhost ~]# docker ps -l
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
    bea707b2a8fe        centos:latest       "/bin/bash"         12 minutes ago      Exited (1) 10 seconds ago                       gloomy_lovelace  
    

    13.查看所有容器

    [root@localhost ~]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                         PORTS               NAMES
    bea707b2a8fe        centos:latest       "/bin/bash"            57 minutes ago      Exited (1) 45 minutes ago                          gloomy_lovelace           
    b277a4166ab8        centos:latest       "ip addr show"         About an hour ago   Exited (0) About an hour ago                       serene_wozniak            
    73c047bbe330        centos:latest       "cat /etc/redhat-rel   About an hour ago   Exited (0) About an hour ago                       grave_engelbart           
    bede20e06f63        centos:latest       "ip addr list"         About an hour ago   Exited (0) About an hour ago                       backstabbing_archimedes   
    c020c244cf45        centos:latest       "/bin/bash/ifconfig"   About an hour ago                                                      drunk_poitras             
    c0c0cd10496a        centos:latest       "ifconfig"             About an hour ago                                                      insane_feynman            
    c556e811dd9e        centos:latest       "echo hello,world"     About an hour ago   Exited (0) About an hour ago                       thirsty_curie             
    17c79f9e410f        centos:latest       "echo hello,world"     About an hour ago   Exited (0) About an hour ago                       backstabbing_galileo      
    

      容器ID              镜像                        执行的命令                   创建时间                状态                                       对外端口号                      昵称 

    14.删除镜像

    [root@localhost ~]# docker images
    REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    ansible/centos7-ansible   latest              231b24a3be84        12 hours ago        400.5 MB
    centos                    latest              0f73ae75014f        2 days ago          172.3 MB
    ubuntu                    latest              91e54dfb1179        2 weeks ago         188.3 MB
    <none>                    <none>              f1b10cd84249        4 months ago        0 B
    [root@localhost ~]# docker rmi f1b10cd84249
    Deleted: f1b10cd842498c23d206ee0cbeaa9de8d2ae09ff3c7af2723a9e337a6965d639
    

    15.删除容器

    [root@localhost ~]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                         PORTS               NAMES
    bea707b2a8fe        centos:latest       "/bin/bash"            About an hour ago   Exited (1) 50 minutes ago                          gloomy_lovelace           
    b277a4166ab8        centos:latest       "ip addr show"         About an hour ago   Exited (0) About an hour ago                       serene_wozniak            
    c020c244cf45        centos:latest       "/bin/bash/ifconfig"   About an hour ago                                                      drunk_poitras             
    [root@localhost ~]# docker rm c020c244cf45 
    c020c244cf45
    

     16.删除所有容器

    [root@localhost ~]# docker rm `docker ps -a -q`
    1a73fe793f0a
    c41b97e2fe06
    101b802d8c5c
    

    -a 列出所有容器 -q只列出容器的ID

      

     

  • 相关阅读:
    A3纸双面打印对折页设置方法
    BAD SYSTEM CONFIG INFO蓝屏解决办法
    局域网内Win7系统怎么开启远程桌面
    word批量删除换行符
    excel复制到word,表格格式错乱解决办法
    word取消回车自动编号
    被深信服上网行为管理器AC拒绝的操作如何正常访问
    震旦AD248复印机如何复印身份证正反面
    Win10开机后黑屏需强制关机再开机才能进桌面怎么办
    Windows已经发现此文件有一个问题
  • 原文地址:https://www.cnblogs.com/XYJK1002/p/4798587.html
Copyright © 2020-2023  润新知