• Docker之常用命令


    全局选项

    1. --config string Location of client config files (default "/root/.docker")
    2. -D, --debug Enable debug mode
    3. -H, --host list Daemon socket(s) to connect to
    4. -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
    5. --tls Use TLS; implied by --tlsverify
    6. --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
    7. --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
    8. --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
    9. --tlsverify Use TLS and verify the remote
    10. -v, --version Print version information and quit

    管理命令

    config 配置

    deploy Deploy a new stack or update an existing stack
    ls List stacks
    ps List the tasks in the stack
    rm Remove one or more stacks
    services List the services in the stack

    container 容器

    • attach Attach local standard input, output, and error streams to a running container

    • commit Create a new image from a container's changes

    • cp Copy files/folders between a container and the local filesystem

    • create Create a new container

    • diff Inspect changes to files or directories on a container's filesystem

    • exec Run a command in a running container

    • export Export a container's filesystem as a tar archive

    • inspect Display detailed information on one or more containers

    • kill Kill one or more running containers

    • logs Fetch the logs of a container

    • ls List containers

    • pause Pause all processes within one or more containers

    • port List port mappings or a specific mapping for the container

    • prune Remove all stopped containers

    • rename Rename a container

    • restart Restart one or more containers

    • rm Remove one or more containers

    • run Run a command in a new container

      • -d, --detach=false 指定容器运行于前台还是后台,默认为false
      • -i, --interactive=false 打开STDIN,用于控制台交互
      • -t, --tty=false 分配tty设备,该可以支持终端登录,默认为false
      • -u, --user="" 指定容器的用户
      • -a, --attach=[] 登录容器(必须是以docker run -d启动的容器)
      • -w, --workdir="" 指定容器的工作目录
      • -c, --cpu-shares=0 设置容器CPU权重,在CPU共享场景使用
      • -e, --env=[] 指定环境变量,容器中可以使用该环境变量
      • -m, --memory="" 指定容器的内存上限
      • -P, --publish-all=false 指定容器暴露的端口
      • -p, --publish=[] 指定容器暴露的端口
      • -h, --hostname="" 指定容器的主机名
      • -v, --volume=[] 给容器挂载存储卷,挂载到容器的某个目录
      • --volumes-from=[] 给容器挂载其他容器上的卷,挂载到容器的某个目录
      • --cap-add=[] 添加权限,权限清单详见:http://linux.die.net/man/7/capabilities
      • --cap-drop=[] 删除权限,权限清单详见:http://linux.die.net/man/7/capabilities
      • --cidfile="" 运行容器后,在指定文件中写入容器PID值,一种典型的监控系统用法
      • --cpuset="" 设置容器可以使用哪些CPU,此参数可以用来容器独占CPU
      • --device=[] 添加主机设备给容器,相当于设备直通
      • --dns=[] 指定容器的dns服务器
      • --dns-search=[] 指定容器的dns搜索域名,写入到容器的/etc/resolv.conf文件
      • --entrypoint="" 覆盖image的入口点
      • --env-file=[] 指定环境变量文件,文件格式为每行一个环境变量
      • --expose=[] 指定容器暴露的端口,即修改镜像的暴露端口
      • --link=[] 指定容器间的关联,使用其他容器的IP、env等信息
      • --lxc-conf=[] 指定容器的配置文件,只有在指定--exec-driver=lxc时使用
      • --name="" 指定容器名字,后续可以通过名字进行容器管理,links特性需要使用名字
      • --net="bridge" 容器网络设置:
        bridge 使用docker daemon指定的网桥
        host //容器使用主机的网络
        container:NAME_or_ID >//使用其他容器的网路,共享IP和PORT等网络资源
        none 容器使用自己的网络(类似--net=bridge),但是不进行配置
      • --privileged=false 指定容器是否为特权容器,特权容器拥有所有的capabilities
      • --restart="no" 指定容器停止后的重启策略:
        no:容器退出时不重启
        on-failure:容器故障退出(返回值非零)时重启
        always:容器退出时总是重启
      • --rm=false 指定容器停止后自动删除容器(不支持以docker run -d启动的容器)
      • --sig-proxy=true 设置由代理接受并处理信号,但是SIGCHLD、SIGSTOP和SIGKILL不能被代理
    • start Start one or more stopped containers

    • stats Display a live stream of container(s) resource usage statistics

    • stop Stop one or more running containers

    • top Display the running processes of a container

    • unpause Unpause all processes within one or more containers

    • update Update configuration of one or more containers

    • wait Block until one or more containers stop, then print their exit codes

    image 镜像

    • build Build an image from a Dockerfile
    • history Show the history of an image
    • import Import the contents from a tarball to create a filesystem image
    • inspect Display detailed information on one or more images
    • load Load an image from a tar archive or STDIN
    • ls List images
    • prune Remove unused images
    • pull Pull an image or a repository from a registry
    • push Push an image or a repository to a registry
    • rm Remove one or more images
    • save Save one or more images to a tar archive (streamed to STDOUT by default)
    • tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

    network 网络

    • connect Connect a container to a network
    • create Create a network
    • disconnect Disconnect a container from a network
    • inspect Display detailed information on one or more networks
    • ls List networks
    • prune Remove all unused networks
    • rm Remove one or more networks

    node 节点

    • demote Demote one or more nodes from manager in the swarm
    • inspect Display detailed information on one or more nodes
    • ls List nodes in the swarm
    • promote Promote one or more nodes to manager in the swarm
    • ps List tasks running on one or more nodes, defaults to current node
    • rm Remove one or more nodes from the swarm
    • update Update a node

    plugin 插件

    • create Create a plugin from a rootfs and configuration. Plugin data directory must - contain config.json and rootfs directory.
    • disable Disable a plugin
    • enable Enable a plugin
    • inspect Display detailed information on one or more plugins
    • install Install a plugin
    • ls List plugins
    • push Push a plugin to a registry
    • rm Remove one or more plugins
    • set Change settings for a plugin
    • upgrade Upgrade an existing plugin

    secret 密文字典

    • create Create a secret from a file or STDIN as content
    • inspect Display detailed information on one or more secrets
    • ls List secrets
    • rm Remove one or more secrets

    system 系统

    • df Show docker disk usage
    • events Get real time events from the server
    • info Display system-wide information
    • prune Remove unused data

    trust 内容信任

    • key Manage keys for signing Docker images
    • signer Manage entities who can sign Docker images
    • inspect Return low-level information about keys and signatures
    • revoke Remove trust for an image
    • sign Sign an image

    volume 持久卷

    • create Create a volume
    • inspect Display detailed information on one or more volumes
    • ls List volumes
    • prune Remove all unused local volumes
    • rm Remove one or more volumes

    service 服务

    Manage services

    stack

    Manage Docker stacks

    swarm

    Manage Swarm

    单独命令映射到管理命令

    Docker 1.12命令行大摡有40个顶级命令。虽然这些命令处理得很好但存在一些问题:

    • 命令列表没有任何组织。对新手来说很难入门以及学习这些命令。(#8756
    • 有些命令,例如docker inspect也没有提供足够的上下文来说明他们是作用于镜像还是容器。这种镜像和容器的命令混合会带来困惑。(#13509
    • 缺乏命令名称的一致性。例如docker images是给所有镜像列表,而docker ps是给出容器列表。这些都有命名不一致的问题。(#8829
    • 有些命令像buildrun被大量使用,还有那些神秘的像pausewait命令却不经常使用。保持所有命令在同一个级别似乎不是很公平。

    Docker 1.13修复了这些问题。命令映射表如下:

    build   image build         从一个Dockerfile构建镜像
    commit  container commit    从一个容器的修改创建一个新的镜像
    cp      container cp        在容器与本地文件系统之间复制文件/文件夹
    create  container create    创建新的容器
    diff    container diff      检阅一个容器文件系统的修改
    events  system events       获取服务器的实时时间
    exec    container exec      在运行的容器内执行命令
    export  container export    打包一个容器文件系统到tar文件
    history image history       展示镜像历史信息
    images  image ls            展示镜像列表
    import  image import        用tar文件导入并创建镜像文件
    info    system info         展示整个系统信息
    inspect container inspect   展示一个容器/镜像或者任务的底层信息
    kill    container kill      终止一个或者多个运行中的容器
    load    image load          从tar文件或者标准输入载入镜像
    login   login               登录Docker registry
    logout  logout              从Docker registry登出
    logs    container logs      获取容器的日志
    network network             管理Docker网络
    node    node                管理Docker Swarm节点
    pause   container pause     暂停一个或者多个容器的所有进程
    port    container port      展示容器的端口映射
    ps      container ls        展示容器列表
    pull    image pull          从某个registry拉取镜像或者仓库
    push    image push          推送镜像或者仓库到某个registry
    rename  container rename    重命名容器
    restart container restart   重启容器
    rm      container rm        移除一个或多个容器
    rmi     image rm            移除一个或多个镜像
    run     container run       运行一个新的容器
    save    image save          打包一个或多个镜像到tar文件(默认是到标准输出)
    search  search              在Docker Hub搜索镜像
    service service             管理Docker services
    start   container start     启动一个或者多个容器
    stats   container stats     获取容器的实时资源使用统计
    stop    container stop      停止一个或多个运行容器
    swarm   swarm               管理Docker Swarm
    tag     image tag           标记一个镜像到仓库
    top     container top       展示容器运行进程
    unpause container unpause   解除暂停一个或多个容器的所有进程
    update  container update    更新一个或多个容器的配置
    version version             显示Docker版本信息
    volume  volume              管理Docker volumes
    wait    container wait      阻塞直到容器停止,然后打印退出代码
    

    常用命令

    删除所有悬空镜像,不删除未使用镜像

    docker rmi $(docker images -f "dangling=true" -q)

  • 相关阅读:
    创建类以及引用一个类
    修改hosts文件
    微信第三方登录接口开发
    Android定位
    Leetcode 102. Binary Tree Level Order Traversal
    Leetcode 725. Split Linked List in Parts
    Leetcode 445. Add Two Numbers II
    Leetcode 328. Odd Even Linked List
    Leetcode 237. Delete Node in a Linked List
    Leetcode 234. Palindrome Linked List
  • 原文地址:https://www.cnblogs.com/yungyu16/p/12603134.html
Copyright © 2020-2023  润新知