Docker常用命令总结

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显示所有的容器包括未运行的

1

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]
posted @ 2019-03-25 21:55  不懂技术的技术宅  阅读(3182)  评论(0编辑  收藏  举报