Q132284591 发表于 2018-5-29 09:00:48

docker 命令

  学了一段时间docker了,公司也已经用docker跑起应用了,为了方便后期的查看稍稍总结了一下。
  查看详情:
  docker --help
  docker command --help (例子:docker run --help)
  ----------------------------------------------------------------------------------------------------------
  attach    Attach to a running container
    build     Build an image from a Dockerfile
    commit    Create a new image from a container's changes
    cp      Copy files/folders from a container's filesystem to the host path
    create    Create a new container
    diff      Inspect changes on a container's filesystem
    events    Get real time events from the server
    exec    Run a command in a running container
    export    Stream the contents of a container as a tar archive
    history   Show the history of an image
    images    List images
    import    Create a new filesystem image from the contents of a tarball
    info      Display system-wide information
    inspect   Return low-level information on a container or image
    kill    Kill a running container
    load      Load an image from a tar archive
    login   Register or log in to a Docker registry server
    logout    Log out from a Docker registry server
    logs      Fetch the logs of a container
    pause   Pause all processes within a container
    port      Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
    ps      List containers
    pull      Pull an image or a repository from a Docker registry server
    push      Push an image or a repository to a Docker registry server
    rename    Rename an existing container
    restart   Restart a running container
    rm      Remove one or more containers
    rmi       Remove one or more images
    run       Run a command in a new container
    save      Save an image to a tar archive
    search    Search for an image on the Docker Hub
    start   Start a stopped container
    stats   Display a stream of a containers' resource usage statistics
    stop      Stop a running container
    tag       Tag an image into a repository
    top       Lookup the running processes of a container
    unpause   Unpause a paused container
    version   Show the Docker version information
    wait      Block until a container stops, then print its exit code

  ----------------------------------------------------------------------------------------------------------
  1. docker version
显示 Docker 版本信息。
  2. docker info
显示 Docker 系统信息,包括镜像和容器数。
  3. docker search
docker search term
--automated=false    Only show automated builds (只列出 automated build
类型的镜像;)
--help=false         Print usage
--no-trunc=false   Don't truncate output (可显示完整的镜像描述;)
-s, --stars=0      Only displays with at least x stars (列出收藏数不小于X的镜像。 )
  4. docker pull
docker pull [-a "o">] name[:tag "o">]
docker pull laozhu/telescope:latest
  从 Docker Hub 中拉取或者更新指定镜像。
-a 拉取所有 tagged 镜像 。
  5. docker login
root@moon:~# docker login
Username: username
Password: ****
Email: user@domain.com
Login Succeeded
Usage: docker login
  Register or log in to a Docker registry server, if no server is
specified "https://index.docker.io/v1/" is the default.
  -e, --email=       Email
--help=false       Print usage
-p, --password=    Password
-u, --username=    Username
  6. docker logout
运行后从指定服务器登出,默认为官方服务器。
  7. docker images
docker images
列出本地所有镜像。其中 对镜像名称进行关键词查询。
-a 列出所有镜像(含过程镜像);
-f 过滤镜像,如: -f ['dangling=true'] 只列出满足
dangling=true 条件的镜像;
--no-trunc 可显示完整的镜像ID;
-q 仅列出镜像ID。
--tree 以树状结构列出镜像的所有提交历史。
  8. docker ps
列出所有运行中容器。
-a 列出所有容器(含沉睡镜像);
--before="nginx" 列出在某一容器之前创建的容器,接受容器名称和ID作为参数;
--since="nginx" 列出在某一容器之后创建的容器,接受容器名称和ID作为参数;
-f 列出满足
exited=<int> 条件的容器;
-l 仅列出最新创建的一个容器;
--no-trunc 显示完整的容器ID;
-n=4 列出最近创建的4个容器;
-q 仅列出容器ID;
-s 显示容器大小。
  9. docker rmi
docker rmi <image>"o">
docker rmi nginx:latest postgres:latest python:latest
从本地移除一个或多个指定的镜像。
-f 强行移除该镜像,即使其正被使用;
--no-prune 不移除该镜像的过程镜像,默认移除。
  10. docker rm
docker rm <container>"o">
docker rm nginx-01 nginx-02 db-01 db-02
sudo docker rm -l /webapp/redis
-f 强行移除该容器,即使其正在运行;
-l 移除容器间的网络连接,而非容器本身;
-v 移除与容器关联的空间。
  11. docker history
docker history"o"> <image>
查看指定镜像的创建历史。
--no-trunc 显示完整的提交记录;
-q 仅列出提交记录ID。
  12. docker start|stop|restart
docker start|stop "p">|restart <container>"o">
启动、停止和重启一个或多个指定容器。
-a 待完成
-i 启动一个容器并进入交互模式;
-t 10 停止或者重启容器的超时时间(秒),超时后系统将杀死进程。
  13. docker kill
docker kill"o"> <container>"o">
杀死一个或多个指定容器进程。
-s "KILL" 自定义发送至容器的信号。
  14. docker events
docker events
docker events --since= "s2">"20141020"
docker events --until= "s2">"20120310"
从服务器拉取个人动态,可选择时间区间。
  15. docker save
docker save -i "debian.tar"
docker save > "debian.tar"
将指定镜像保存成 tar 归档文件, docker load 的逆操作。保存后再加载(saved-loaded)的镜像不会丢失提交历史和层,可以回滚。
-o "debian.tar" 指定保存的镜像归档。
  16. docker load
docker load
docker load < debian.tar
docker load -i "debian.tar"
从 tar 镜像归档中载入镜像, docker save 的逆操作。保存后再加载(saved-loaded)的镜像不会丢失提交历史和层,可以回滚。
-i "debian.tar" 指定载入的镜像归档。
  17. docker export
docker export <container>
docker export nginx-01 > export.tar
将指定的容器保存成 tar 归档文件, docker import 的逆操作。导出后导入(exported-imported))的容器会丢失所有的提交历史,无法回滚。
  18. docker import
docker import url|-"o">]
cat export.tar"p">| docker import - imported-nginx:latest
docker import http://example.com/export.tar
  从归档文件(支持远程文件)创建一个镜像, export 的逆操作,可为导入镜像打上标签。导出后导入(exported-imported))的容器会丢失所有的提交历史,无法回滚。
  19. docker top
docker top <running_container>"o">
查看一个正在运行容器进程,支持 ps 命令参数。
  20. docker inspect
docker instpect nginx:latest
docker inspect nginx-container
检查镜像或者容器的参数,默认返回 JSON 格式。
-f 指定返回值的模板文件。
  21. docker pause
暂停某一容器的所有进程。
  22. docker unpause
docker unpause <container>
恢复某一容器的所有进程。
  23. docker tag
docker tag <image>[:tag "o">] name "o">[:tag]
标记本地镜像,将其归入某一仓库。
-f 覆盖已有标记。
  24. docker push
docker push name[:tag "o">]
docker push laozhu/nginx:latest
将镜像推送至远程仓库,默认为 Docker Hub 。
  25. docker logs
docker logs <container>
docker logs -f -t --tail= "s2">"10" insane_babbage
获取容器运行时的输出日志。
-f 跟踪容器日志的最近更新;
-t 显示容器日志的时间戳;
--tail="10" 仅列出最新10条容器日志。
  26. docker run
docker run <image> [ "nb">command]"o">
启动一个容器,在其中运行指定命令。
-a stdin 指定标准输入输出内容类型,可选 STDIN/
STDOUT / STDERR 三项;
-d 后台运行容器,并返回容器ID;
-i 以交互模式运行容器,通常与 -t 同时使用;
-t 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
--name="nginx-lb" 为容器指定一个名称;
--dns 8.8.8.8 指定容器使用的DNS服务器,默认和宿主一致;
--dns-search example.com 指定容器DNS搜索域名,默认和宿主一致;
-h "mars" 指定容器的hostname;
-e username="ritchie" 设置环境变量;
--env-file=[] 从指定文件读入环境变量;
--cpuset="0-2" or --cpuset="0,1,2"
绑定容器到指定CPU运行;
-c cpu共享
-m 限制内存
--net="bridge" 指定容器的网络连接类型,支持 bridge /
host / none
container:<name|id> 四种类型;
--link=[] 添加链接到另一个容器
--expose=[] 设置一个端口或者一个范围
-v绑定挂载卷
--device=[] 主机设备添加到容器中
------------------------------------------------------------------
-a, --attach=[]             Attach to STDIN, STDOUT or STDERR
--add-host=[]               Add a custom host-to-IP mapping (host:ip)
--blkio-weight=0            Block IO (relative weight), between 10 and 1000
-c, --cpu-shares=0          CPU shares (relative weight)
--cap-add=[]                Add Linux capabilities
--cap-drop=[]               Drop Linux capabilities
--cgroup-parent=            Optional parent cgroup for the container
--cidfile=                  Write the container ID to the file
--cpu-period=0            Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota=0               Limit the CPU CFS quota
--cpuset-cpus=            CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems=            MEMs in which to allow execution (0-3, 0,1)
-d, --detach=false          Run container in background and print container ID
--device=[]               Add a host device to the container
--dns=[]                  Set custom DNS servers
--dns-search=[]             Set custom DNS search domains
-e, --env=[]                Set environment variables
--entrypoint=               Overwrite the default ENTRYPOINT of the image
--env-file=[]               Read in a file of environment variables
--expose=[]               Expose a port or a range of ports
-h, --hostname=             Container host name
--help=false                Print usage
-i, --interactive=false   Keep STDIN open even if not attached
--ipc=                      IPC namespace to use
-l, --label=[]            Set meta data on a container
--label-file=[]             Read in a line delimited file of labels
--link=[]                   Add link to another container
--log-driver=               Logging driver for container
--log-opt=[]                Log driver options
--lxc-conf=[]               Add custom lxc options
-m, --memory=               Memory limit
--mac-address=            Container MAC address (e.g. 92:d0:c6:0a:29:33)
--memory-swap=            Total memory (memory + swap), '-1' to disable swap
--name=                     Assign a name to the container
--net=bridge                Set the Network mode for the container
--oom-kill-disable=false    Disable OOM Killer
-P, --publish-all=false   Publish all exposed ports to random ports
-p, --publish=[]            Publish a container's port(s) to the host
--pid=                      PID namespace to use
--privileged=false          Give extended privileges to this container
--read-only=false         Mount the container's root filesystem as read only
--restart=no                Restart policy to apply when a container exits
--rm=false                  Automatically remove the container when it exits
--security-opt=[]         Security Options
--sig-proxy=true            Proxy received signals to the process
-t, --tty=false             Allocate a pseudo-TTY
-u, --user=               Username or UID (format: <name|uid>[:<group|gid>])
--ulimit=[]               Ulimit options
--uts=                      UTS namespace to use
-v, --volume=[]             Bind mount a volume
--volumes-from=[]         Mount volumes from the specified container(s)
-w, --workdir=            Working directory inside the container
  借鉴:http://www.server110.com/docker/201411/11122.html,在他的基础上补充了一下,并标出常用和重点。
页: [1]
查看完整版本: docker 命令