目錄
1. 查看docker版本
docker --version
2.查看docker安裝詳細信息
docker info
3.測試docker是否安裝成功
docker run hello-world
## 出現如下信息為安裝成功
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
4.查看所有已安裝的鏡像
docker images
5.刪除一個鏡像
docker rmi [image ID | Repository]
6.查看運行的容器信息
docker ps [-a] # 加上-a顯示所有的容器包括未運行的
7.運行一個鏡像
docker run --name [container name] -t -i [image ID | Repository:TAG] /bin/bash
*-t 選項讓Docker分配一個偽終端(pseudo-tty)並綁定到容器的標准輸入上, -i 則讓容器的標准輸入保持打開
*這里若TAG是latest可以不指定
8. 停止、啟動、恢復、刪除容器
docker stop [container name | container ID]
docker start [container name | container ID]
docker attach [container name | container ID] # 恢復容器到命名行,輸完指令需要按一次enter
docker rm [-f] [container name | container ID] # -f 強制刪除正在運行的容器
9.掛載本地目錄到鏡像
docker run -v [local folder path]:[container mounted path] --name [container name] -t -i [image ID | repository name] : TAG] /bin/bash
示例:
docker run -v /home/hz/caffe:/workspace -t -i --name caffe bvlc/caffe:gpu /bin/bash
10.容器重命名
docker rename [original name] [new name]
11.查看容器詳細信息
docker inspect [container name | container id]
12.將本地文件上傳到容器內
docker cp [local file path] [container id]:[container file path]