Docker 入门私人笔记(十六)回顾和总结3 - 命令 docker 和 docker-compose 的区别

Docker-Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排。是 harbor 的默认容器编排工具。

  • docker 命令可以查看和操作宿主机中所有正在运行的容器;
  • docker-compose 只能看到和操作由它负责管理的正在运行的容器(本次实操中能看到组成 harbor 服务的所有容器。此时还并未向 harbor 提交任何镜像),而看不到也不能操作用 docker 命令部署的容器。例如:后者看不到 mydocker 这个容器:

    [root@k8s-master /data]# docker start mydocker
    mydocker
    [root@k8s-master /data]# 
    [root@k8s-master /data]# docker ps
    CONTAINER ID        IMAGE                                                    COMMAND                  CREATED             STATUS                   PORTS                       NAMES
    dfc449918143        goharbor/harbor-jobservice:v1.9.1                        "/harbor/harbor_jobs…"   6 hours ago         Up 6 hours (healthy)                                 harbor-jobservice
    c0fbf43a4c94        goharbor/nginx-photon:v1.9.1                             "nginx -g 'daemon of…"   6 hours ago         Up 6 hours (healthy)     0.0.0.0:80->8080/tcp        nginx
    ca2f560f89b0        goharbor/harbor-core:v1.9.1                              "/harbor/harbor_core"    6 hours ago         Up 6 hours (healthy)                                 harbor-core
    3d94c08a202e        goharbor/harbor-portal:v1.9.1                            "nginx -g 'daemon of…"   6 hours ago         Up 6 hours (healthy)     8080/tcp                    harbor-portal
    67e04d48d8d6        goharbor/redis-photon:v1.9.1                             "redis-server /etc/r…"   6 hours ago         Up 6 hours (healthy)     6379/tcp                    redis
    2d7d3d209834        goharbor/harbor-db:v1.9.1                                "/docker-entrypoint.…"   6 hours ago         Up 6 hours (healthy)     5432/tcp                    harbor-db
    70f5f7392eeb        goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.9.1   "/entrypoint.sh /etc…"   6 hours ago         Up 5 minutes (healthy)   5000/tcp                    registry
    fa8811cc14a3        goharbor/harbor-registryctl:v1.9.1                       "/harbor/start.sh"       6 hours ago         Up 6 hours (healthy)                                 registryctl
    cf7b6f399df5        goharbor/harbor-log:v1.9.1                               "/bin/sh -c /usr/loc…"   6 hours ago         Up 6 hours (healthy)     127.0.0.1:1514->10514/tcp   harbor-log
    2bc93c16c234        centos                                                   "/bin/bash"              5 weeks ago         Up 10 seconds                                        mydocker
    [root@k8s-master /data]# 
    [root@k8s-master /data]# docker-compose ps
        Name                     Command                  State                 Ports          
    ---------------------------------------------------------------------------------------------
    harbor-core         /harbor/harbor_core              Up (healthy)                            
    harbor-db           /docker-entrypoint.sh            Up (healthy)   5432/tcp                 
    harbor-jobservice   /harbor/harbor_jobservice  ...   Up (healthy)                            
    harbor-log          /bin/sh -c /usr/local/bin/ ...   Up (healthy)   127.0.0.1:1514->10514/tcp
    harbor-portal       nginx -g daemon off;             Up (healthy)   8080/tcp                 
    nginx               nginx -g daemon off;             Up (healthy)   0.0.0.0:80->8080/tcp     
    redis               redis-server /etc/redis.conf     Up (healthy)   6379/tcp                 
    registry            /entrypoint.sh /etc/regist ...   Up (healthy)   5000/tcp                 
    registryctl         /harbor/start.sh                 Up (healthy)
    [root@k8s-master /data/dockerfile/app/harbor/harbor]# docker-compose stop mydocker
    ERROR: No such service: mydocker
    [root@k8s-master /data/dockerfile/app/harbor/harbor]# docker-compose stop 2bc93c16c234
    ERROR: No such service: 2bc93c16c234

同理,docker images 和 docker-compose images 命令的区别也类似。

  • 前者可以看到全部镜像。
  • 后者只能看到部署 harbor 时的那些镜像。

    [root@k8s-master /data/dockerfile/app/harbor/harbor]# docker images
    REPOSITORY                         TAG                             IMAGE ID            CREATED             SIZE
    192.168.100.151:5000/app/jenkins   latest                          83644f08fe7a        29 hours ago        660MB
    runtime/tomcat                     latest                          df043eca9357        4 days ago          581MB
    system/centos                      v3                              80213e8e91cd        5 days ago          308MB
    system/centos                      v2                              b824207c3f4f        5 days ago          304MB
    system/centos                      v1                              3f0198aa6b0c        5 days ago          303MB
    goharbor/chartmuseum-photon        v0.9.0-v1.9.1                   0aa7451af9b8        3 weeks ago         131MB
    goharbor/harbor-migrator           v1.9.1                          a83f1be1ec94        3 weeks ago         362MB
    goharbor/redis-photon              v1.9.1                          4d8d79a557df        3 weeks ago         110MB
    goharbor/clair-photon              v2.0.9-v1.9.1                   98b318ca3cb0        3 weeks ago         165MB
    goharbor/notary-server-photon      v0.6.1-v1.9.1                   78dac4ed14d8        3 weeks ago         138MB
    goharbor/notary-signer-photon      v0.6.1-v1.9.1                   5d9f413e14a8        3 weeks ago         135MB
    goharbor/harbor-registryctl        v1.9.1                          f4b2b72cdf71        3 weeks ago         99.6MB
    goharbor/registry-photon           v2.7.1-patch-2819-2553-v1.9.1   d460d658f383        3 weeks ago         82.3MB
    goharbor/nginx-photon              v1.9.1                          0db1e12b9d30        3 weeks ago         43.9MB
    goharbor/harbor-log                v1.9.1                          368dd79ef99f        3 weeks ago         82.5MB
    goharbor/harbor-jobservice         v1.9.1                          71d4a3eaff94        3 weeks ago         141MB
    goharbor/harbor-core               v1.9.1                          d105210d9924        3 weeks ago         155MB
    goharbor/harbor-portal             v1.9.1                          2dced1823043        3 weeks ago         51.3MB
    goharbor/harbor-db                 v1.9.1                          91784692a954        3 weeks ago         147MB
    goharbor/prepare                   v1.9.1                          44775181c88d        3 weeks ago         148MB
    copy-nginx                         latest                          ab56bba91343        5 weeks ago         126MB
    nginx                              latest                          ab56bba91343        5 weeks ago         126MB
    centos                             latest                          67fa590cfc1c        2 months ago        202MB
    192.168.100.151:5000/registry      latest                          f32a97de94e1        7 months ago        25.8MB
    registry                           latest                          f32a97de94e1        7 months ago        25.8MB
    [root@k8s-master /data/dockerfile/app/harbor/harbor]# 
    [root@k8s-master /data/dockerfile/app/harbor/harbor]# docker-compose images
      Container               Repository                         Tag                  Image Id      Size  
    --------------------------------------------------------------------------------------------------------
    harbor-core         goharbor/harbor-core          v1.9.1                          d105210d9924   148 MB 
    harbor-db           goharbor/harbor-db            v1.9.1                          91784692a954   140 MB 
    harbor-jobservice   goharbor/harbor-jobservice    v1.9.1                          71d4a3eaff94   134 MB 
    harbor-log          goharbor/harbor-log           v1.9.1                          368dd79ef99f   78.7 MB
    harbor-portal       goharbor/harbor-portal        v1.9.1                          2dced1823043   48.9 MB
    nginx               goharbor/nginx-photon         v1.9.1                          0db1e12b9d30   41.9 MB
    redis               goharbor/redis-photon         v1.9.1                          4d8d79a557df   105 MB 
    registry            goharbor/registry-photon      v2.7.1-patch-2819-2553-v1.9.1   d460d658f383   78.5 MB
    registryctl         goharbor/harbor-registryctl   v1.9.1                          f4b2b72cdf71   95 MB 

你可能感兴趣的:(Docker 入门私人笔记(十六)回顾和总结3 - 命令 docker 和 docker-compose 的区别)