(三)、Docker常用基础命令

1、Docker 帮助命令

帮助命令:

  1. docker version 查看版本
  2. docker info 查询docker详细信息
  3. docker --help 查看命令帮助
2、Docker 镜像命令
  1. docker images 查看docker镜像
  2. docker images -a 列出本地所有的镜像(含中间映像层)
  3. docker images -q 只显示镜像ID
  4. docker images --digests 显示镜像的摘要信息
  5. docker images --no-trunc 显示完整的镜像信息
  6. docker search hello-world 搜索hello-world镜像
  7. docker search hello-world --no-trunc 搜索显示完整的镜像描述
  8. docker search hello-world -s 10 搜索列出收藏数不小于指定值(10)的镜像。
  9. docker search hello-world --automated 搜索只列出 automated build类型的镜像
  10. docker pull hello-world 拉取hello-world镜像
  11. docker pull hello-world[:01] 拉取hello-world镜像01标签
  12. docker rmi -f 镜像ID 删除单个镜像
  13. docker rmi -f 镜像名1:TAG 镜像名2:TAG 删除多个镜像
  14. docker rmi -f $(docker images -qa) 删除全部
  15. docker rmi 镜像 删除镜像
3、Docker 容器命令

有镜像才能创建容器,这是根本前提docker pull centos

新建并启动容器:docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

OPTIONS说明(常用):有些是一个减号,有些是两个减号

--name="容器新名字": 为容器指定一个名称;
-d: 后台运行容器,并返回容器ID,也即启动守护式容器;
-i:以交互模式运行容器,通常与 -t 同时使用;
-t:为容器重新分配一个伪输入终端,通常与 -i 同时使用;
-P: 随机端口映射;
-p: 指定端口映射,有以下四种格式
      ip:hostPort:containerPort
      ip::containerPort
      hostPort:containerPort
      containerPort
#使用镜像centos:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。
docker run -it centos /bin/bash 
  1. docker run -it --name=os-01 centos 运行一个OS
  2. docker start containerid 启动容器
  3. docker stop centainerid 停止一个容器
  4. docker kill centainerid 强行停止一个容器
  5. docker rm centainerid 删除已停止的容器
  6. docker exec -it centainerid /bin/bash 进入容器
  7. docker attach centainerid 重新进入

查看容器日志

  1. docker logs -f -t --tail 500 centainerName 只看容器的倒数500行日志

查看容器内部细节:

  1. docker inspect centainerid

查看容器内运行的进程:

  1. docker top 容器ID

从容器内拷贝文件到主机上:

  1. docker cp 容器ID:容器内路径 目的主机路径
posted @ 2020-07-27 13:24  日落西风又在吹  阅读(1341)  评论(0编辑  收藏  举报