1、Docker 幫助命令
幫助命令:
- docker version 查看版本
- docker info 查詢docker詳細信息
- docker --help 查看命令幫助
2、Docker 鏡像命令
- docker images 查看docker鏡像
- docker images -a 列出本地所有的鏡像(含中間映像層)
- docker images -q 只顯示鏡像ID
- docker images --digests 顯示鏡像的摘要信息
- docker images --no-trunc 顯示完整的鏡像信息
- docker search hello-world 搜索hello-world鏡像
- docker search hello-world --no-trunc 搜索顯示完整的鏡像描述
- docker search hello-world -s 10 搜索列出收藏數不小於指定值(10)的鏡像。
- docker search hello-world --automated 搜索只列出 automated build類型的鏡像
- docker pull hello-world 拉取hello-world鏡像
- docker pull hello-world[:01] 拉取hello-world鏡像01標簽
- docker rmi -f 鏡像ID 刪除單個鏡像
- docker rmi -f 鏡像名1:TAG 鏡像名2:TAG 刪除多個鏡像
- docker rmi -f $(docker images -qa) 刪除全部
- 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
- docker run -it --name=os-01 centos 運行一個OS
- docker start containerid 啟動容器
- docker stop centainerid 停止一個容器
- docker kill centainerid 強行停止一個容器
- docker rm centainerid 刪除已停止的容器
- docker exec -it centainerid /bin/bash 進入容器
- docker attach centainerid 重新進入
查看容器日志
- docker logs -f -t --tail 500 centainerName 只看容器的倒數500行日志
查看容器內部細節:
- docker inspect centainerid
查看容器內運行的進程:
- docker top 容器ID
從容器內拷貝文件到主機上:
- docker cp 容器ID:容器內路徑 目的主機路徑