$ sudo docker # docker 命令幫助 Commands: attach Attach to a running container # 當前 shell 下 attach 鏈接指定運行鏡像 build Build an image from a Dockerfile # 經過 Dockerfile 定製鏡像 commit Create a new image from a container's changes # 提交當前容器爲新的鏡像 cp Copy files/folders from the containers filesystem to the host path # 從容器中拷貝指定文件或者目錄到宿主機中 create Create a new container # 建立一個新的容器,同 run,但不啓動容器 diff Inspect changes on a container's filesystem # 查看 docker 容器變化 events Get real time events from the server # 從 docker 服務獲取容器實時事件 exec Run a command in an existing container # 在已存在的容器上運行命令 export Stream the contents of a container as a tar archive # 導出容器的內容流做爲一個 tar 歸檔文件[對應 import ] history Show the history of an image # 展現一個鏡像造成歷史 images List images # 列出系統當前鏡像 import Create a new filesystem image from the contents of a tarball # 從tar包中的內容建立一個新的文件系統映像[對應 export] info Display system-wide information # 顯示系統相關信息 inspect Return low-level information on a container # 查看容器詳細信息 kill Kill a running container # kill 指定 docker 容器 load Load an image from a tar archive # 從一個 tar 包中加載一個鏡像[對應 save] login Register or Login to the docker registry server # 註冊或者登錄一個 docker 源服務器 logout Log out from a Docker registry server # 從當前 Docker registry 退出 logs Fetch the logs of a container # 輸出當前容器日誌信息 port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT # 查看映射端口對應的容器內部源端口 pause Pause all processes within a container # 暫停容器 ps List containers # 列出容器列表 pull Pull an image or a repository from the docker registry server # 從docker鏡像源服務器拉取指定鏡像或者庫鏡像 push Push an image or a repository to the docker registry server # 推送指定鏡像或者庫鏡像至docker源服務器 restart Restart a running container # 重啓運行的容器 rm Remove one or more containers # 移除一個或者多個容器 rmi Remove one or more images # 移除一個或多個鏡像[無容器使用該鏡像纔可刪除,不然需刪除相關容器纔可繼續或 -f 強制刪除] run Run a command in a new container # 建立一個新的容器並運行一個命令 save Save an image to a tar archive # 保存一個鏡像爲一個 tar 包[對應 load] search Search for an image on the Docker Hub # 在 docker hub 中搜索鏡像 start Start a stopped containers # 啓動容器 stop Stop a running containers # 中止容器 tag Tag an image into a repository # 給源中鏡像打標籤 top Lookup the running processes of a container # 查看容器中運行的進程信息 unpause Unpause a paused container # 取消暫停容器 version Show the docker version information # 查看 docker 版本號 wait Block until a container stops, then print its exit code # 截取容器中止時的退出狀態值 Run 'docker COMMAND --help' for more information on a command.
# 在ubuntu中安裝docker $ sudo apt-get install docker.io # 查看docker的版本信息 $ docker version # 查看安裝docker的信息 $ docker info # 查看本機Docker中存在哪些鏡像 $ docker images # 檢索image $ docker search ubuntu:14.04# 在docker中獲取ubuntu鏡像 $ docker pull ubuntu:14.04# 顯示一個鏡像的歷史 $ docker history birdben/ubuntu:v1 # 列出一個容器裏面被改變的文件或者目 $ docker diff birdben/ubuntu:v1 # 從一個容器中取日誌 $ docker logs birdben/ubuntu:v1 # 顯示一個運行的容器裏面的進程信息 $ docker top birdben/ubuntu:v1 # 從容器裏面拷貝文件/目錄到本地一個路徑 $ docker cp ID:/container_path to_path # 列出當前全部正在運行的容器 $ docker ps # 列出全部的容器 $ docker ps -a # 列出最近一次啓動的容器 $ docker ps -l # 查看容器的相關信息 $ docker inspect $CONTAINER_ID # 顯示容器IP地址和端口號,若是輸出是空的說明沒有配置IP地址(不一樣的Docker容器能夠經過此IP地址互相訪問) $ docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID # 保存對容器的修改 $ docker commit -m "Added ssh from ubuntu14.04" -a "birdben"6s56d43f627f3 birdben/ubuntu:v1 # 參數:# -m參數用來來指定提交的說明信息;# -a能夠指定用戶信息的;# 6s56d43f627f3表明的時容器的id;# birdben/ubuntu:v1指定目標鏡像的用戶名、倉庫名和 tag 信息。# 構建一個容器 $ docker build -t="birdben/ubuntu:v1" . # 參數:# -t爲構建的鏡像制定一個標籤,便於記憶/索引等# . 指定Dockerfile文件在當前目錄下,也能夠替換爲一個具體的 Dockerfile 的路徑。# 在docker中運行ubuntu鏡像 $ docker run <相關參數> <鏡像 ID> <初始命令> # 守護模式啓動 $ docker run -it ubuntu:14.04# 交互模式啓動 $ docker run -it ubuntu:14.04 /bin/bash # 指定端口號啓動 $ docker run -p 80:80 birdben/ubuntu:v1 # 指定配置啓動 $ sudo docker run -d -p 10.211.55.4:9999:22 birdben/ubuntu:v1 '/usr/sbin/sshd' -D # 參數:# -d:表示以「守護模式」執行,日誌不會出如今輸出終端上。# -i:表示以「交互模式」運行容器,-i 則讓容器的標準輸入保持打開# -t:表示容器啓動後會進入其命令行,-t 選項讓Docker分配一個僞終端(pseudo-tty)並綁定到容器的標準輸入上# -v:表示須要將本地哪一個目錄掛載到容器中,格式:-v <宿主機目錄>:<容器目錄>,-v 標記來建立一個數據卷並掛載到容器裏。在一次 run 中屢次使用能夠掛載多個數據卷。# -p:表示宿主機與容器的端口映射,此時將容器內部的 22 端口映射爲宿主機的 9999 端口,這樣就向外界暴露了 9999 端口,可經過 Docker 網橋來訪問容器內部的 22 端口了。# 注意:這裏使用的是宿主機的 IP 地址:10.211.55.4,與對外暴露的端口號 9999,它映射容器內部的端口號 22。ssh外部須要訪問:ssh root@10.211.55.4 -p 9999# 不必定要使用「鏡像 ID」,也可使用「倉庫名:標籤名」# start 啓動容器 $ docker start 117843ade696117843ade696 # stop 中止正在運行的容器 $ docker stop 117843ade696117843ade696 # restart 重啓容器 $ docker restart 117843ade696117843ade696 # rm 刪除容器 $ docker rm 117843ade696117843ade696 # rmi 刪除鏡像 $ docker rmi ed9c93747fe1Deleted # 登陸Docker Hub中心 $ docker login # 發佈上傳image(push) $ docker push birdben/ubuntu:v1docker