• Docker:Docker命令(帮助命令、镜像命令、容器命令)


    1、帮助命令

    (1)查看版本

    [zhaihuabing@aubin ~]$ docker version
    Client: Docker Engine - Community
     Version:           19.03.13
     API version:       1.40
     Go version:        go1.13.15
     Git commit:        4484c46d9d
     Built:             Wed Sep 16 17:03:45 2020
     OS/Arch:           linux/amd64
     Experimental:      false
    Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/dock
    er.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version: dial unix /var/run/docker.sock: connect: permission denied

    (2)查看信息

    [root@aubin zhaihuabing]# docker info
    Client:
     Debug Mode: false
    
    Server:
     Containers: 1
      Running: 0
      Paused: 0
      Stopped: 1
     Images: 1
     Server Version: 19.03.13
     Storage Driver: overlay2
      Backing Filesystem: xfs
      Supports d_type: true
      Native Overlay Diff: true
     Logging Driver: json-file
     Cgroup Driver: cgroupfs
     Plugins:
      Volume: local
      Network: bridge host ipvlan macvlan null overlay
      Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
     Swarm: inactive
     Runtimes: runc
     Default Runtime: runc
     Init Binary: docker-init
     containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
     runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
     init version: fec3683
     Security Options:
      seccomp
       Profile: default
     Kernel Version: 3.10.0-862.el7.x86_64
     Operating System: CentOS Linux 7 (Core)
     OSType: linux
     Architecture: x86_64
     CPUs: 1
     Total Memory: 1.716GiB
     Name: aubin.com
     ID: G75I:WTBP:DTBH:OE5X:2TBY:YSFU:IRWY:SQ6A:64TQ:LBPO:5FJD:EBZ5
     Docker Root Dir: /var/lib/docker
     Debug Mode: false
     Registry: https://index.docker.io/v1/
     Labels:
     Experimental: false
     Insecure Registries:
      127.0.0.0/8
     Registry Mirrors:
      https://xx6x4grv.mirror.aliyuncs.com/
     Live Restore Enabled: false

    2、镜像命令

    (1)列出本地主机上的镜像

    (2)列出本地所有的镜像

    [root@aubin zhaihuabing]# docker images -a
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    hello-world         latest              bf756fb1ae65        9 months ago        13.3kB

    (3)只显示镜像ID

    [root@aubin zhaihuabing]# docker images -q
    bf756fb1ae65

    (4)显示镜像的摘要信息

    [root@aubin zhaihuabing]# docker images --digests
    REPOSITORY          TAG                 DIGEST                                                                    IMAGE ID            CREATED             SIZE
    hello-world         latest              sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0   bf756fb1ae65        9 months ago        13.3kB

    (5)显示完整的摘要信息

    [root@aubin zhaihuabing]# docker images --no-trunc
    REPOSITORY          TAG                 IMAGE ID                                                                  CREATED             SIZE
    hello-world         latest              sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b   9 months ago        13.3kB

    (6)查找镜像

    查找所有:

    [root@aubin zhaihuabing]# docker search tomcat
    NAME                          DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    tomcat                        Apache Tomcat is an open source implementati…   2856                [OK]                
    tomee                         Apache TomEE is an all-Apache Java EE certif…   83                  [OK]                
    dordoka/tomcat                Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base55                                      [OK]
    bitnami/tomcat                Bitnami Tomcat Docker Image                     36                                      [OK]
    kubeguide/tomcat-app          Tomcat image for Chapter 1                      29                                      
    consol/tomcat-7.0             Tomcat 7.0.57, 8080, "admin/admin"              17                                      [OK]
    cloudesire/tomcat             Tomcat server, 6/7/8                            15                                      [OK]
    aallam/tomcat-mysql           Debian, Oracle JDK, Tomcat & MySQL              13                                      [OK]
    arm32v7/tomcat                Apache Tomcat is an open source implementati…   10                                      
    maluuba/tomcat7-java8         Tomcat7 with java8.                             6                                       
    rightctrl/tomcat              CentOS , Oracle Java, tomcat application ssl…   6                                       [OK]
    unidata/tomcat-docker         Security-hardened Tomcat Docker container.      4                                       [OK]
    arm64v8/tomcat                Apache Tomcat is an open source implementati…   2                                       
    amd64/tomcat                  Apache Tomcat is an open source implementati…   2                                       
    jelastic/tomcat               An image of the Tomcat Java application serv…   2                                       
    99taxis/tomcat7               Tomcat7                                         1                                       [OK]
    cfje/tomcat-resource          Tomcat Concourse Resource                       1                                       
    camptocamp/tomcat-logback     Docker image for tomcat with logback integra…   1                                       [OK]
    chenyufeng/tomcat-centos      tomcat基于centos6的镜像                              1                                       [OK]
    ppc64le/tomcat                Apache Tomcat is an open source implementati…   1                                       
    oobsri/tomcat8                Testing CI Jobs with different names.           1                                       
    softwareplant/tomcat          Tomcat images for jira-cloud testing            0                                       [OK]
    picoded/tomcat7               tomcat7 with jre8 and MANAGER_USER / MANAGER…   0                                       [OK]
    secoresearch/tomcat-varnish   Tomcat and Varnish 5.0                          0                                       [OK]
    s390x/tomcat                  Apache Tomcat is an open source implementati…   0    

    按照点赞数查找(点赞数超过300):

    [root@aubin zhaihuabing]# docker search -s 300 tomcat
    Flag --stars has been deprecated, use --filter=stars=3 instead
    NAME                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    tomcat              Apache Tomcat is an open source implementati…   2856                [OK]   

    (7)拉取一个镜像(默认是最新版本)

    (8)删除

    [root@aubin zhaihuabing]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    tomcat              latest              891fcd9c5b3a        8 days ago          647MB
    hello-world         latest              bf756fb1ae65        9 months ago        13.3kB
    [root@aubin zhaihuabing]# docker rmi hello-world
    Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container bc1eb5ae64a3 is using its referenced image bf756fb1ae65
    [root@aubin zhaihuabing]# docker rmi -f hello-world
    Untagged: hello-world:latest
    Untagged: hello-world@sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
    Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
    [root@aubin zhaihuabing]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    tomcat              latest              891fcd9c5b3a        8 days ago          647MB

    3、容器命令

    (1)拉取一个centos

    [root@aubin zhaihuabing]# docker pull centos
    Using default tag: latest
    latest: Pulling from library/centos
    3c72a8ed6814: Pull complete 
    Digest: sha256:76d24f3ba3317fa945743bb3746fbaf3a0b752f10b10376960de01da70685fbd
    Status: Downloaded newer image for centos:latest
    docker.io/library/centos:latest

     这个centos是在docker中运行的,与虚拟机上运行的centos是不一样的,因为容器是一个简易版的

     (2)运行centos

     查看进程:

    [root@aubin zhaihuabing]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    c97f6b1619c6        0d120b6ccaa8        "/bin/bash"         4 minutes ago       Up 4 minutes                            stoic_cartwright

    (3)退出容器

    关闭容器并退出:

    [root@c97f6b1619c6 /]# exit
    exit
    [root@aubin zhaihuabing]#

    查看进程:

    [root@aubin zhaihuabing]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

    查看历史容器记录:

    [root@aubin zhaihuabing]# docker ps -l
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                            PORTS               NAMES
    c97f6b1619c6        0d120b6ccaa8        "/bin/bash"         9 minutes ago       Exited (127) About a minute ago                       stoic_cartwright
    [root@aubin zhaihuabing]# 

    (4)容器别名

    [root@aubin zhaihuabing]# docker run -it --name 2020zhaihuabing centos

    查看:

    [root@aubin zhaihuabing]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    02efa6625c43        centos              "/bin/bash"         37 seconds ago      Up 34 seconds                           2020zhaihuabing

    (5)退出但是不关闭

    ctrl+p+q

    查看进程,进程依旧存在:

    [root@aubin zhaihuabing]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    02efa6625c43        centos              "/bin/bash"         4 minutes ago       Up 4 minutes                            2020zhaihuabing

    (6)守护方式启动(后台运行)

    [root@aubin zhaihuabing]# docker run -d centos
    892d78a363b0bb3659b765085618d335cbb4459bf7710fbfa2f45ff3a9bf5864

    (7)以json的格式显示容器信息

    [root@aubin zhaihuabing]# docker inspect f51ae14801c4
    [
        {
            "Id": "f51ae14801c495aa4175ef7ab2ec06c668cbc87351f0a37eb903a1255b4da6fe",
            "Created": "2020-10-22T08:41:03.199497107Z",
            "Path": "/bin/bash",
            "Args": [],
            "State": {
                "Status": "running",
                "Running": true,
                "Paused": false,
                "Restarting": false,
                "OOMKilled": false,
                "Dead": false,
                "Pid": 57202,
                "ExitCode": 0,
                "Error": "",
                "StartedAt": "2020-10-22T08:41:04.280774452Z",
                "FinishedAt": "0001-01-01T00:00:00Z"
            },
            "Image": "sha256:0d120b6ccaa8c5e149176798b3501d4dd1885f961922497cd0abef155c869566",
            "ResolvConfPath": "/var/lib/docker/containers/f51ae14801c495aa4175ef7ab2ec06c668cbc87351f0a37eb903a1255b4da6fe/resolv.conf",
            "HostnamePath": "/var/lib/docker/containers/f51ae14801c495aa4175ef7ab2ec06c668cbc87351f0a37eb903a1255b4da6fe/hostname",
            "HostsPath": "/var/lib/docker/containers/f51ae14801c495aa4175ef7ab2ec06c668cbc87351f0a37eb903a1255b4da6fe/hosts",
            "LogPath": "/var/lib/docker/containers/f51ae14801c495aa4175ef7ab2ec06c668cbc87351f0a37eb903a1255b4da6fe/f51ae14801c495aa4175ef7ab2ec06c668cbc87351f0a37eb903a1255b4da6fe-json.log",
            "Name": "/jolly_perlman",
            "RestartCount": 0,
            "Driver": "overlay2",
            "Platform": "linux",
            "MountLabel": "",
            "ProcessLabel": "",
            "AppArmorProfile": "",
            "ExecIDs": null,
            "HostConfig": {
                "Binds": null,
                "ContainerIDFile": "",
                "LogConfig": {
                    "Type": "json-file",
                    "Config": {}
                },
                "NetworkMode": "default",
                "PortBindings": {},
                "RestartPolicy": {
                    "Name": "no",
                    "MaximumRetryCount": 0
                },
                "AutoRemove": false,
                "VolumeDriver": "",
                "VolumesFrom": null,
                "CapAdd": null,
                "CapDrop": null,
                "Capabilities": null,
                "Dns": [],
                "DnsOptions": [],
                "DnsSearch": [],
                "ExtraHosts": null,
                "GroupAdd": null,
                "IpcMode": "private",
                "Cgroup": "",
                "Links": null,
                "OomScoreAdj": 0,
                "PidMode": "",
                "Privileged": false,
                "PublishAllPorts": false,
                "ReadonlyRootfs": false,
                "SecurityOpt": null,
                "UTSMode": "",
                "UsernsMode": "",
                "ShmSize": 67108864,
                "Runtime": "runc",
                "ConsoleSize": [
                    0,
                    0
                ],
                "Isolation": "",
                "CpuShares": 0,
                "Memory": 0,
                "NanoCpus": 0,
                "CgroupParent": "",
                "BlkioWeight": 0,
                "BlkioWeightDevice": [],
                "BlkioDeviceReadBps": null,
                "BlkioDeviceWriteBps": null,
                "BlkioDeviceReadIOps": null,
                "BlkioDeviceWriteIOps": null,
                "CpuPeriod": 0,
                "CpuQuota": 0,
                "CpuRealtimePeriod": 0,
                "CpuRealtimeRuntime": 0,
                "CpusetCpus": "",
                "CpusetMems": "",
                "Devices": [],
                "DeviceCgroupRules": null,
                "DeviceRequests": null,
                "KernelMemory": 0,
                "KernelMemoryTCP": 0,
                "MemoryReservation": 0,
                "MemorySwap": 0,
                "MemorySwappiness": null,
                "OomKillDisable": false,
                "PidsLimit": null,
                "Ulimits": null,
                "CpuCount": 0,
                "CpuPercent": 0,
                "IOMaximumIOps": 0,
                "IOMaximumBandwidth": 0,
                "MaskedPaths": [
                    "/proc/asound",
                    "/proc/acpi",
                    "/proc/kcore",
                    "/proc/keys",
                    "/proc/latency_stats",
                    "/proc/timer_list",
                    "/proc/timer_stats",
                    "/proc/sched_debug",
                    "/proc/scsi",
                    "/sys/firmware"
                ],
                "ReadonlyPaths": [
                    "/proc/bus",
                    "/proc/fs",
                    "/proc/irq",
                    "/proc/sys",
                    "/proc/sysrq-trigger"
                ]
            },
            "GraphDriver": {
                "Data": {
                    "LowerDir": "/var/lib/docker/overlay2/5289975d8f2a43847ef4158ac6d8cbe13764c39997dd38519f35bbbf5065dee5-init/diff:/var/lib/docker/overlay2/8877a450ded8d6ab9c3a2afe8055e541cb64ea025c742836ba7a07f8c408b6a3/diff",
                    "MergedDir": "/var/lib/docker/overlay2/5289975d8f2a43847ef4158ac6d8cbe13764c39997dd38519f35bbbf5065dee5/merged",
                    "UpperDir": "/var/lib/docker/overlay2/5289975d8f2a43847ef4158ac6d8cbe13764c39997dd38519f35bbbf5065dee5/diff",
                    "WorkDir": "/var/lib/docker/overlay2/5289975d8f2a43847ef4158ac6d8cbe13764c39997dd38519f35bbbf5065dee5/work"
                },
                "Name": "overlay2"
            },
            "Mounts": [],
            "Config": {
                "Hostname": "f51ae14801c4",
                "Domainname": "",
                "User": "",
                "AttachStdin": true,
                "AttachStdout": true,
                "AttachStderr": true,
                "Tty": true,
                "OpenStdin": true,
                "StdinOnce": true,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ],
                "Cmd": [
                    "/bin/bash"
                ],
                "Image": "centos",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": {
                    "org.label-schema.build-date": "20200809",
                    "org.label-schema.license": "GPLv2",
                    "org.label-schema.name": "CentOS Base Image",
                    "org.label-schema.schema-version": "1.0",
                    "org.label-schema.vendor": "CentOS"
                }
            },
            "NetworkSettings": {
                "Bridge": "",
                "SandboxID": "d5d512e039244da356feac706eeb5a38a04ed5e2917c6ce8290ac3491a88cf28",
                "HairpinMode": false,
                "LinkLocalIPv6Address": "",
                "LinkLocalIPv6PrefixLen": 0,
                "Ports": {},
                "SandboxKey": "/var/run/docker/netns/d5d512e03924",
                "SecondaryIPAddresses": null,
                "SecondaryIPv6Addresses": null,
                "EndpointID": "d99f836b72f7fde9765c3f7876b5fdb77418bfe59caa54a50d8bcf115e44d74e",
                "Gateway": "172.17.0.1",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "IPAddress": "172.17.0.3",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "MacAddress": "02:42:ac:11:00:03",
                "Networks": {
                    "bridge": {
                        "IPAMConfig": null,
                        "Links": null,
                        "Aliases": null,
                        "NetworkID": "e0f7a0b462b78f38895dc255df617fecaab09c6a9fe868022519fd818f4b4167",
                        "EndpointID": "d99f836b72f7fde9765c3f7876b5fdb77418bfe59caa54a50d8bcf115e44d74e",
                        "Gateway": "172.17.0.1",
                        "IPAddress": "172.17.0.3",
                        "IPPrefixLen": 16,
                        "IPv6Gateway": "",
                        "GlobalIPv6Address": "",
                        "GlobalIPv6PrefixLen": 0,
                        "MacAddress": "02:42:ac:11:00:03",
                        "DriverOpts": null
                    }
                }
            }
        }
    ]
    [root@aubin zhaihuabing]
    每个人都会有一段异常艰难的时光 。 生活的压力 , 工作的失意 , 学业的压力。 爱的惶惶不可终日。 挺过来的 ,人生就会豁然开朗。 挺不过来的 ,时间也会教你 ,怎么与它们握手言和 ,所以不必害怕的。 ——杨绛
  • 相关阅读:
    我的周记8——"因为相信,所以看见"
    我的周记7——“阳光开朗,自信表达一切”
    一些做设计挺不错的网站
    我的周记6——"不破楼兰誓不还“
    版本管理工具 Git
    我的周记5——"侵略如火,不动如山"
    SQLite-FMDatabase用法
    UIImage与Base64相互转换
    百度地图--地图标注的重复单击
    百度地图的单例模式
  • 原文地址:https://www.cnblogs.com/zhai1997/p/13859293.html
Copyright © 2020-2023  润新知