zoukankan      html  css  js  c++  java
  • docker常用命令

    • 查看docker信息
    docker info
    • 搜索镜像包
    docker search [OPTIONS] TERM

    比如 :

    docker search ubuntu
    • 下载镜像包
    docker pull [OPTIONS] NAME[:TAG|@DIGEST]

    使用命令 docker pull 来下载镜像。

    比如:

    docker pull ubuntu:18.04
    • 删除已下载镜像
    docker rmi imageID
    • 创建一个新的容器并运行一个命令
    docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

    比如,前台运行:

    docker run -t -i ubuntu:18.04 /bin/bash

    后台运行:

    docker run -t -d ubuntu:18.04

    后台运行并进行端口映射:

    docker run -t -d -p 0.0.0.0:10022:22/tcp ubuntu:18.04
    
    使用本机的10022端口映射docker容器的22端口。
    • 进入正运行的容器
    docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

    比如:

    docker exec -it 1023d897691d /bin/bash
    
    # 其中,1023d897691d 为容器id
    • 查看运行容器列表
    Usage:  docker ps [OPTIONS]
    
    List containers
    
    Options:
      -a, --all             Show all containers (default shows just running)
      -f, --filter filter   Filter output based on conditions provided
          --format string   Pretty-print containers using a Go template
      -n, --last int        Show n last created containers (includes all states) (default -1)
      -l, --latest          Show the latest created container (includes all states)
          --no-trunc        Don't truncate output
      -q, --quiet           Only display numeric IDs
      -s, --size            Display total file sizes

    比如,

    查看当前运行容器列表: docker ps

    查看所有容器列表(含异常退出的) : docker ps -a

    显示完整输出(即不会截断输出) : docker ps -a --no-trunc

    显示最后被创建的 3 个容器 : docker ps -n 3

    显示容器文件大小 :docker ps -s

    • 管理容器
    停用镜像:docker stop ImageID
    删除容器: docker rm ID
    重启镜像: docker start imageID
    删除容器: docker rm ID
    • 导出镜像文件
    docker save -o [导出后的文件名] [镜像名称]

    如,将test-0.1.0:test镜像导出为test-0.1.0.tar:

    docker save -o test-0.1.0.tar test-0.1.0:test
    • 导入镜像文件
    docker load –input [导出后的文件名]

    如,将上面导出的test-0.1.0.tar再导入:

    docker load –input test-0.1.0.tar
    • 查看容器日志
    Usage:  docker logs [OPTIONS] CONTAINER
    
    Fetch the logs of a container
    
    Options:
          --details        Show extra details provided to logs
      -f, --follow         Follow log output
          --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
          --tail string    Number of lines to show from the end of the logs (default "all")
      -t, --timestamps     Show timestamps
          --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)

    比如,查看日志:

    docker logs CONTAINER_ID

    查看最近15分钟日志:

    docker logs --since 15m CONTAINER_ID

    查看特定时间段的日志:

    docker logs -t --since="2019-11-01T12:00:00" --until "2019-11-21T12:00:00" CONTAINER_ID

    本文github地址:

    https://github.com/mike-zhang/mikeBlogEssays/blob/master/2019/20191121_docker常用命令.rst

    欢迎补充

  • 相关阅读:
    IP 地址无效化
    上升下降字符串
    STL-----map
    只出现一次的数字
    4的幂
    GDI+_入门教程【一】
    大白话系列之C#委托与事件讲解(二)
    大白话系列之C#委托与事件讲解(二)
    大白话系列之C#委托与事件讲解(一)
    大白话系列之C#委托与事件讲解(一)
  • 原文地址:https://www.cnblogs.com/MikeZhang/p/docker_20191121.html
Copyright © 2011-2022 走看看