Docker入門系列(二)--docker操做命令

查看Docker版本

  • docker --version
docker --version
//輸出
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        634eae
 Built:             Wed Nov 13 07:22:34 2019
 OS/Arch:           darwin/amd64
 Experimental:      false
複製代碼

登錄Docker倉庫

  • docker login docker.io
song@song:~|⇒  docker login docker.io
Username (song):
Password:
login success!
複製代碼

鏡像相關命令

  • 搜索鏡像
docker search elasticsearch
//輸出
NAME                                 DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
elasticsearch                        Elasticsearch is a powerful open source sear…   4267                [OK]
nshou/elasticsearch-kibana           Elasticsearch-7.5.1 Kibana-7.5.1                118                                     [OK]
itzg/elasticsearch                   Provides an easily configurable Elasticsearc…   70                                      [OK]
mobz/elasticsearch-head              elasticsearch-head front-end and standalone …   58
elastichq/elasticsearch-hq           Official Docker image for ElasticHQ: Elastic…   48                                      [OK]
elastic/elasticsearch                The Elasticsearch Docker image maintained by…   29
bitnami/elasticsearch                Bitnami Docker Image for Elasticsearch          28                                      [OK]
taskrabbit/elasticsearch-dump        Import and export tools for elasticsearch       20                                      [OK]
lmenezes/elasticsearch-kopf          elasticsearch kopf                              18                                      [OK]
barnybug/elasticsearch               Latest Elasticsearch 1.7.2 and previous rele…   17                                      [OK]
複製代碼
  • 獲取鏡像
docker pull elasticsearch:latest
複製代碼
  • 更新鏡像版本或者鏡像名稱
docker tag nodejs:latest nodejs:v1
docker tag nodejs:v1 docker.io/xxx/nodejs:v1
複製代碼
  • 構建鏡像
docker build -t test:latest -f Dockerfile .
複製代碼
  • 發佈鏡像
docker push docker.io/xxx/nodejs:v1
複製代碼
  • 刪除鏡像
docker rmi nodejs:v1
複製代碼
  • 刪除鏡像
docker rmi $(docker images | grep "none" | awk '{print $3}') 
複製代碼
  • 查看鏡像詳細信息
docker inspect nodejs:v1
複製代碼

容器相關命令

  • 運行容器
docker run -d --name elasticsearch --restart=always -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms512m -Xmx512m" elasticsearch:6.7.1
複製代碼
  • 中止容器
docker stop elasticsearch
複製代碼
  • 刪除容器
docker rm elasticsearch
複製代碼
  • 重啓容器
docker restart elasticsearch
複製代碼
  • 查看容器日誌
docker exec elasticsearch -it /bin/bash
複製代碼
  • 查看容器詳細信息
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' elasticsearch
複製代碼

網絡相關命令

  • 查看網絡鏈接列表
docker network ls
//輸出
NETWORK ID          NAME                DRIVER              SCOPE
12b42610291a        bridge              bridge              local
b37807026f86        host                host                local
d61f9f7674a3        none                null                local
複製代碼
  • 查看一個或者多個網絡信息
docker network inspect host
或
docker network inspect host none
//輸出
[
    {
        "Name": "host",
        "Id": "xxxxxxxxxx",
        "Created": "2020-02-14T03:19:05.612424113Z",
        "Scope": "local",
        "Driver": "host",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": []
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
複製代碼
  • 鏈接容器到網絡
docker network connect host [容器名稱]
複製代碼
  • 建立網絡鏈接
docker network create bridge2
複製代碼
  • 斷開網絡鏈接
docker network disconnect host [容器名稱]
複製代碼
  • 刪除一個或多個網絡
docker network rm host
複製代碼
  • 刪除全部不使用的網絡
docker network prune
複製代碼
相關文章
相關標籤/搜索