學了一段時間docker了,公司也已經用docker跑起應用了,爲了方便後期的查看稍稍總結了一下。
查看詳情:
docker --help
docker command --help (例子:docker run --help)
----------------------------------------------------------------------------------------------------------
attach Attach to a running container
build Build an p_w_picpath from a Dockerfile
commit Create a new p_w_picpath from a container's changes
cp Copy files/folders from a container's filesystem to the host path
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Stream the contents of a container as a tar archive
history Show the history of an p_w_picpath
p_w_picpaths List p_w_picpaths
import Create a new filesystem p_w_picpath from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container or p_w_picpath
kill Kill a running container
load Load an p_w_picpath from a tar archive
login Register or log in to a Docker registry server
logout Log out from a Docker registry server
logs Fetch the logs of a container
pause Pause all processes within a container
port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
ps List containers
pull Pull an p_w_picpath or a repository from a Docker registry server
push Push an p_w_picpath or a repository to a Docker registry server
rename Rename an existing container
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more p_w_picpaths
run Run a command in a new container
save Save an p_w_picpath to a tar archive
search Search for an p_w_picpath on the Docker Hub
start Start a stopped container
stats Display a stream of a containers' resource usage statistics
stop Stop a running container
tag Tag an p_w_picpath into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the Docker version information
wait Block until a container stops, then print its exit code
----------------------------------------------------------------------------------------------------------
1. docker version
顯示 Docker 版本信息。
2. docker info
顯示 Docker 系統信息,包括鏡像和容器數。
3. docker search
docker search [options "o">] term
--automated=false Only show automated builds (只列出 automated build
類型的鏡像;)
--help=false Print usage
--no-trunc=false Don't truncate output (可顯示完整的鏡像描述;)
-s, --stars=0 Only displays with at least x stars (列出收藏數不小於X的鏡像。 )
4. docker pull
docker pull [-a "o">] [user/ "o">]name[:tag "o">]
docker pull laozhu/telescope:latest
從 Docker Hub 中拉取或者更新指定鏡像。
-a 拉取所有 tagged 鏡像 。
5. docker login
root@moon:~# docker login
Username: username
Password: ****
Email: [email protected]
Login Succeeded
Usage: docker login [OPTIONS] [SERVER]
Register or log in to a Docker registry server, if no server is
specified "https://index.docker.io/v1/" is the default.
-e, --email= Email
--help=false Print usage
-p, --password= Password
-u, --username= Username
6. docker logout
運行後從指定服務器登出,默認爲官方服務器。
7. docker p_w_picpaths
docker p_w_picpaths [options "o">] [name]
列出本地所有鏡像。其中 [name] 對鏡像名稱進行關鍵詞查詢。
-a 列出所有鏡像(含過程鏡像);
-f 過濾鏡像,如: -f ['dangling=true'] 只列出滿足
dangling=true 條件的鏡像;
--no-trunc 可顯示完整的鏡像ID;
-q 僅列出鏡像ID。
--tree 以樹狀結構列出鏡像的所有提交歷史。
8. docker ps
列出所有運行中容器。
-a 列出所有容器(含沉睡鏡像);
--before="nginx" 列出在某一容器之前創建的容器,接受容器名稱和ID作爲參數;
--since="nginx" 列出在某一容器之後創建的容器,接受容器名稱和ID作爲參數;
-f [exited=<int>] 列出滿足
exited=<int> 條件的容器;
-l 僅列出最新創建的一個容器;
--no-trunc 顯示完整的容器ID;
-n=4 列出最近創建的4個容器;
-q 僅列出容器ID;
-s 顯示容器大小。
9. docker rmi
docker rmi [options "o">] <p_w_picpath> "o">[p_w_picpath...]
docker rmi nginx:latest postgres:latest python:latest
從本地移除一個或多個指定的鏡像。
-f 強行移除該鏡像,即使其正被使用;
--no-prune 不移除該鏡像的過程鏡像,默認移除。
10. docker rm
docker rm [options "o">] <container> "o">[container...]
docker rm nginx-01 nginx-02 db-01 db-02
sudo docker rm -l /webapp/redis
-f 強行移除該容器,即使其正在運行;
-l 移除容器間的網絡連接,而非容器本身;
-v 移除與容器關聯的空間。
11. docker history
docker history "o">[options] <p_w_picpath>
查看指定鏡像的創建歷史。
--no-trunc 顯示完整的提交記錄;
-q 僅列出提交記錄ID。
12. docker start|stop|restart
docker start|stop "p">|restart [options "o">] <container> "o">[container...]
啓動、停止和重啓一個或多個指定容器。
-a 待完成
-i 啓動一個容器並進入交互模式;
-t 10 停止或者重啓容器的超時時間(秒),超時後系統將殺死進程。
13. docker kill
docker kill "o">[options "o">] <container> "o">[container...]
殺死一個或多個指定容器進程。
-s "KILL" 自定義發送至容器的信號。
14. docker events
docker events [options "o">]
docker events --since= "s2">"20141020"
docker events --until= "s2">"20120310"
從服務器拉取個人動態,可選擇時間區間。
15. docker save
docker save -i "debian.tar"
docker save > "debian.tar"
將指定鏡像保存成 tar 歸檔文件, docker load 的逆操作。保存後再加載(saved-loaded)的鏡像不會丟失提交歷史和層,可以回滾。
-o "debian.tar" 指定保存的鏡像歸檔。
16. docker load
docker load [options]
docker load < debian.tar
docker load -i "debian.tar"
從 tar 鏡像歸檔中載入鏡像, docker save 的逆操作。保存後再加載(saved-loaded)的鏡像不會丟失提交歷史和層,可以回滾。
-i "debian.tar" 指定載入的鏡像歸檔。
17. docker export
docker export <container>
docker export nginx-01 > export.tar
將指定的容器保存成 tar 歸檔文件, docker import 的逆操作。導出後導入(exported-imported))的容器會丟失所有的提交歷史,無法回滾。
18. docker import
docker import url|- "o">[repository[:tag "o">]]
cat export.tar "p">| docker import - imported-nginx:latest
docker import http://example.com/export.tar
從歸檔文件(支持遠程文件)創建一個鏡像, export 的逆操作,可爲導入鏡像打上標籤。導出後導入(exported-imported))的容器會丟失所有的提交歷史,無法回滾。
19. docker top
docker top <running_container> "o">[ps options]
查看一個正在運行容器進程,支持 ps 命令參數。
20. docker inspect
docker instpect nginx:latest
docker inspect nginx-container
檢查鏡像或者容器的參數,默認返回 JSON 格式。
-f 指定返回值的模板文件。
21. docker pause
暫停某一容器的所有進程。
22. docker unpause
docker unpause <container>
恢復某一容器的所有進程。
23. docker tag
docker tag [options "o">] <p_w_picpath>[:tag "o">] [repository/ "o">][username/]name "o">[:tag]
標記本地鏡像,將其歸入某一倉庫。
-f 覆蓋已有標記。
24. docker push
docker push name[:tag "o">]
docker push laozhu/nginx:latest
將鏡像推送至遠程倉庫,默認爲 Docker Hub 。
25. docker logs
docker logs [options "o">] <container>
docker logs -f -t --tail= "s2">"10" insane_babbage
獲取容器運行時的輸出日誌。
-f 跟蹤容器日誌的最近更新;
-t 顯示容器日誌的時間戳;
--tail="10" 僅列出最新10條容器日誌。
26. docker run
docker run [options "o">] <p_w_picpath> [ "nb">command] "o">[arg...]
啓動一個容器,在其中運行指定命令。
-a stdin 指定標準輸入輸出內容類型,可選 STDIN/
STDOUT / STDERR 三項;
-d 後臺運行容器,並返回容器ID;
-i 以交互模式運行容器,通常與 -t 同時使用;
-t 爲容器重新分配一個僞輸入終端,通常與 -i 同時使用;
--name="nginx-lb" 爲容器指定一個名稱;
--dns 8.8.8.8 指定容器使用的DNS服務器,默認和宿主一致;
--dns-search example.com 指定容器DNS搜索域名,默認和宿主一致;
-h "mars" 指定容器的hostname;
-e username="ritchie" 設置環境變量;
--env-file=[] 從指定文件讀入環境變量;
--cpuset="0-2" or --cpuset="0,1,2"
綁定容器到指定CPU運行;
-c cpu共享
-m 限制內存
--net="bridge" 指定容器的網絡連接類型,支持 bridge /
host / none
container:<name|id> 四種類型;
--link=[] 添加鏈接到另一個容器
--expose=[] 設置一個端口或者一個範圍
-v 綁定掛載卷
--device=[] 主機設備添加到容器中
------------------------------------------------------------------
-a, --attach=[] Attach to STDIN, STDOUT or STDERR
--add-host=[] Add a custom host-to-IP mapping (host:ip)
--blkio-weight=0 Block IO (relative weight), between 10 and 1000
-c, --cpu-shares=0 CPU shares (relative weight)
--cap-add=[] Add Linux capabilities
--cap-drop=[] Drop Linux capabilities
--cgroup-parent= Optional parent cgroup for the container
--cidfile= Write the container ID to the file
--cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota=0 Limit the CPU CFS quota
--cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems= MEMs in which to allow execution (0-3, 0,1)
-d, --detach=false Run container in background and print container ID
--device=[] Add a host device to the container
--dns=[] Set custom DNS servers
--dns-search=[] Set custom DNS search domains
-e, --env=[] Set environment variables
--entrypoint= Overwrite the default ENTRYPOINT of the p_w_picpath
--env-file=[] Read in a file of environment variables
--expose=[] Expose a port or a range of ports
-h, --hostname= Container host name
--help=false Print usage
-i, --interactive=false Keep STDIN open even if not attached
--ipc= IPC namespace to use
-l, --label=[] Set meta data on a container
--label-file=[] Read in a line delimited file of labels
--link=[] Add link to another container
--log-driver= Logging driver for container
--log-opt=[] Log driver options
--lxc-conf=[] Add custom lxc options
-m, --memory= Memory limit
--mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33)
--memory-swap= Total memory (memory + swap), '-1' to disable swap
--name= Assign a name to the container
--net=bridge Set the Network mode for the container
--oom-kill-disable=false Disable OOM Killer
-P, --publish-all=false Publish all exposed ports to random ports
-p, --publish=[] Publish a container's port(s) to the host
--pid= PID namespace to use
--privileged=false Give extended privileges to this container
--read-only=false Mount the container's root filesystem as read only
--restart=no Restart policy to apply when a container exits
--rm=false Automatically remove the container when it exits
--security-opt=[] Security Options
--sig-proxy=true Proxy received signals to the process
-t, --tty=false Allocate a pseudo-TTY
-u, --user= Username or UID (format: <name|uid>[:<group|gid>])
--ulimit=[] Ulimit options
--uts= UTS namespace to use
-v, --volume=[] Bind mount a volume
--volumes-from=[] Mount volumes from the specified container(s)
-w, --workdir= Working directory inside the container
借鑑:http://www.server110.com/docker/201411/11122.html,在他的基礎上補充了一下,並標出常用和重點。