- 查看docker資訊
docker info
- 搜索鏡像包
docker search [OPTIONS] TERM
比如 :
docker search ubuntu
- 下載鏡像包
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
使用命令 docker pull 來下載鏡像,
比如:
docker pull ubuntu:18.04
- 洗掉已下載鏡像
docker rmi imageID
- 創建一個新的容器并運行一個命令
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
比如,前臺運行:
docker run -t -i ubuntu:18.04 /bin/bash
后臺運行:
docker run -t -d ubuntu:18.04
后臺運行并進行埠映射:
docker run -t -d -p 0.0.0.0:10022:22/tcp ubuntu:18.04 使用本機的10022埠映射docker容器的22埠,
- 進入正運行的容器
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
比如:
docker exec -it 1023d897691d /bin/bash
# 其中,1023d897691d 為容器id
- 查看運行容器串列
Usage: docker ps [OPTIONS] List containers Options: -a, --all Show all containers (default shows just running) -f, --filter filter Filter output based on conditions provided --format string Pretty-print containers using a Go template -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) --no-trunc Don't truncate output -q, --quiet Only display numeric IDs -s, --size Display total file sizes
比如,
查看當前運行容器串列: docker ps
查看所有容器串列(含例外退出的) : docker ps -a
顯示完整輸出(即不會截斷輸出) : docker ps -a --no-trunc
顯示最后被創建的 3 個容器 : docker ps -n 3
顯示容器檔案大小 :docker ps -s
- 管理容器
停用鏡像:docker stop ImageID 洗掉容器: docker rm ID 重啟鏡像: docker start imageID 洗掉容器: docker rm ID
- 匯出鏡像檔案
docker save -o [匯出后的檔案名] [鏡像名稱]
如,將test-0.1.0:test鏡像匯出為test-0.1.0.tar:
docker save -o test-0.1.0.tar test-0.1.0:test
- 匯入鏡像檔案
docker load –input [匯出后的檔案名]
如,將上面匯出的test-0.1.0.tar再匯入:
docker load –input test-0.1.0.tar
- 查看容器日志
Usage: docker logs [OPTIONS] CONTAINER Fetch the logs of a container Options: --details Show extra details provided to logs -f, --follow Follow log output --since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes) --tail string Number of lines to show from the end of the logs (default "all") -t, --timestamps Show timestamps --until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
比如,查看日志:
docker logs CONTAINER_ID
查看最近15分鐘日志:
docker logs --since 15m CONTAINER_ID
查看特定時間段的日志:
docker logs -t --since="2019-11-01T12:00:00" --until "2019-11-21T12:00:00" CONTAINER_ID
本文github地址:
https://github.com/mike-zhang/mikeBlogEssays/blob/master/2019/20191121_docker常用命令.rst
歡迎補充
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/106043.html
標籤:其他
上一篇:通信網路的多址技術
