(三)、Docker常用基礎命令


1、Docker 幫助命令

幫助命令:

  1. docker version 查看版本
  2. docker info 查詢docker詳細信息
  3. docker --help 查看命令幫助
2、Docker 鏡像命令
  1. docker images 查看docker鏡像
  2. docker images -a 列出本地所有的鏡像(含中間映像層)
  3. docker images -q 只顯示鏡像ID
  4. docker images --digests 顯示鏡像的摘要信息
  5. docker images --no-trunc 顯示完整的鏡像信息
  6. docker search hello-world 搜索hello-world鏡像
  7. docker search hello-world --no-trunc 搜索顯示完整的鏡像描述
  8. docker search hello-world -s 10 搜索列出收藏數不小於指定值(10)的鏡像。
  9. docker search hello-world --automated 搜索只列出 automated build類型的鏡像
  10. docker pull hello-world 拉取hello-world鏡像
  11. docker pull hello-world[:01] 拉取hello-world鏡像01標簽
  12. docker rmi -f 鏡像ID 刪除單個鏡像
  13. docker rmi -f 鏡像名1:TAG 鏡像名2:TAG 刪除多個鏡像
  14. docker rmi -f $(docker images -qa) 刪除全部
  15. docker rmi 鏡像 刪除鏡像
3、Docker 容器命令

有鏡像才能創建容器,這是根本前提docker pull centos

新建並啟動容器:docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

OPTIONS說明(常用):有些是一個減號,有些是兩個減號

--name="容器新名字": 為容器指定一個名稱;
-d: 后台運行容器,並返回容器ID,也即啟動守護式容器;
-i:以交互模式運行容器,通常與 -t 同時使用;
-t:為容器重新分配一個偽輸入終端,通常與 -i 同時使用;
-P: 隨機端口映射;
-p: 指定端口映射,有以下四種格式
      ip:hostPort:containerPort
      ip::containerPort
      hostPort:containerPort
      containerPort
#使用鏡像centos:latest以交互模式啟動一個容器,在容器內執行/bin/bash命令。
docker run -it centos /bin/bash 
  1. docker run -it --name=os-01 centos 運行一個OS
  2. docker start containerid 啟動容器
  3. docker stop centainerid 停止一個容器
  4. docker kill centainerid 強行停止一個容器
  5. docker rm centainerid 刪除已停止的容器
  6. docker exec -it centainerid /bin/bash 進入容器
  7. docker attach centainerid 重新進入

查看容器日志

  1. docker logs -f -t --tail 500 centainerName 只看容器的倒數500行日志

查看容器內部細節:

  1. docker inspect centainerid

查看容器內運行的進程:

  1. docker top 容器ID

從容器內拷貝文件到主機上:

  1. docker cp 容器ID:容器內路徑 目的主機路徑


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM