设为首页 收藏本站
查看: 557|回复: 0

[经验分享] docker命令详解(一)

[复制链接]

尚未签到

发表于 2018-5-29 08:05:20 | 显示全部楼层 |阅读模式
docker [OPTIONS] command
  Usage: docker [OPTIONS] COMMAND [arg...]
  docker daemon [ --help | ... ]
  docker [ -h | --help | -v | --version ]
  A self-sufficient runtime for containers.
  Options:
  --config=~/.docker             Location of client config files
  -D,--debug=false               Enable debug mode
  -H,--host=[]                   Daemonsocket(s) to connect to
  -h,--help=false                Print usage
  -l,--log-level=info            Set the logginglevel
  --tls=false                     Use TLS; implied by--tlsverify
  --tlscacert=~/.docker/ca.pem   Trust certs signed only by this CA
  --tlscert=~/.docker/cert.pem   Path to TLS certificate file
  --tlskey=~/.docker/key.pem     Path to TLS key file
  --tlsverify=false               Use TLS and verify the remote
  -v,--version=false             Print version information and quit
  

attach
  Attach to a running container
  将终端依附到容器上
  Usage:  docker attach [OPTIONS] CONTAINER
  Attach to a running container
  --help=false        Print usage
  --no-stdin=false    Do not attach STDIN
  --sig-proxy=true    Proxy all received signals to the process
  为后端运行的交互式的容器启用一个终端与之交互。
  1.后台有一个可以交互的容器.
DSC0000.png

  2.启动该容器.
DSC0001.png

  3.通过attach启动终端与之交互
DSC0002.png

  

build
  
  Usage:  docker build [OPTIONS] PATH | URL | -
  Build an image from a Dockerfile
  

  --build-arg=[]                  Set build-time variables
  --cpu-shares=0                  CPU shares (relative weight)
  --cgroup-parent=                Optional parent cgroup for the container
  --cpu-period=0                  Limit the CPU CFS (Completely Fair Scheduler) period
  --cpu-quota=0                   Limit the CPU CFS (Completely Fair Scheduler) 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)
  --disable-content-trust=true    Skip image verification
  -f, --file=                     Name of the Dockerfile (Default is 'PATH/Dockerfile')
  --force-rm=false                Always remove intermediate containers
  --help=false                    Print usage
  -m, --memory=                   Memory limit
  --memory-swap=                  Total memory (memory + swap), '-1' to disable swap
  --no-cache=false                Do not use cache when building the image
  --pull=false                    Always attempt to pull a newer version of the image
  -q, --quiet=false               Suppress the verbose output generated by the containers
  --rm=true                       Remove intermediate containers after a successful build
  -t, --tag=                      Repository name (and optionally a tag) for the image
  --ulimit=[]                     Ulimit options
  

  通过Dockerfile创建镜像。具体见以后的使用中。
  

  
commit
  

  Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
  Create a new image from a container's changes
  

  -a, --author=       Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change=[]     Apply Dockerfile instruction to the created image
  --help=false        Print usage
  -m, --message=      Commit message
  -p, --pause=true    Pause container during commit
  
  通过容器创建本地镜像.
  可自定义tag,如docker commit dc806ee0bf86 web:v1
  不指定tag的情况下默认tag为latest
  root@ubuntu:~# docker commit dc806ee0bf86test
  1e488386876e14ef3e930a98ec0bb49de1890963e2e979069f9f4d87f89f4959
DSC0003.png

  

cp
  Usage:  docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|-
  docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH
  

  Copy files/folders between a container and the local filesystem
  Use '-' as the source to read a tar archive from stdin
  and extract it to a directory destination in a container.
  Use '-' as the destination to stream a tar archive of a
  container source to stdout.
  容器和宿主机之间相互copy文件
  1.将容器:/data/a.txt复制到本地当前目录
  # docker cp 87cb69be18bb:/data/a.txt ./
  2.将本地文件复制到容器:/data/backup目录下
  #docker cp helpdocker.tgz87cb69be18bb:/data/backup/
  3.将本地目录复制到容器:/data/backup目录下
  #docker cp data 87cb69be18bb:/data/backup
  

create
  Usage:  docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
  Create a new container
  -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
  --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 CPU CFS (Completely Fair Scheduler) 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)
  --device=[]                     Add a host device to the container
  --disable-content-trust=true    Skip image verification
  --dns=[]                        Set custom DNS servers
  --dns-opt=[]                    Set DNS options
  --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
  --group-add=[]                  Add additional groups to join
  -h, --hostname=                 Container host name
  --help=false                    Print usage
  -i, --interactive=false         Keep STDIN open even if not attached
  --ipc=                          IPC namespace to use
  --kernel-memory=                Kernel memory limit
  -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-reservation=           Memory soft limit
  --memory-swap=                  Total memory (memory + swap), '-1' to disable swap
  --memory-swappiness=-1          Tuning container memory swappiness (0 to 100)
  --name=                         Assign a name to the container
  --net=default                   Set the Network 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
  --security-opt=[]               Security Options
  --stop-signal=SIGTERM           Signal to stop a container, SIGTERM by default
  -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
  --volume-driver=                Optional volume driver for the container
  --volumes-from=[]               Mount volumes from the specified container(s)
  -w, --workdir=                  Working directory inside the container
  创建但不启动一个容器.具体参数同docker run.
  

diff
  Usage:  docker diff [OPTIONS] CONTAINER
  Inspect changes on a container's filesystem
  --help=false       Print usage
  查看容器内发生变化的文件。
  # docker diff 87cb69be18bb
  A /data
  A /data/a.txt
  A /data/b
  A /data/backup
  A /data/backup/data
  A /data/backup/helpdocker.tgz
  C /root
  A /root/.bash_history

events
  Usage:  docker events [OPTIONS]
  Get real time events from the server
  -f, --filter=[]    Filter output based on conditions provided
  --help=false       Print usage
  --since=           Show all events created since timestamp
  --until=           Stream events until this timestamp
  实时输出docker服务器端的事件,包括容器的创建、启动、关闭等。
  # docker events
2016-08-26T10:42:08.001137030+08:00 87cb69be18bbe74ea9e14b16228ccc3347dcffb3e074fa303ca32deb46417105: (from ubuntu:14.04) die

exec
  Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
  Run a command in a running container
  -d, --detach=false         Detached mode: run command in the background
  --help=false               Print usage
  -i, --interactive=false    Keep STDIN open even if not attached
  --privileged=false         Give extended privileges to the command
  -t, --tty=false            Allocate a pseudo-TTY
  -u, --user=                Username or UID (format: <name|uid>[:<group|gid>])
  通过宿主机在正在运行的容器上执行命令。
  通过宿主机在容器上创建文件
  # docker exec 87cb69be18bb touch/root/abc.txt
  可通过exec命令申请一个终端,执行shell
  # docker exec -it 87cb69be18bb /bin/bash
  root@87cb69be18bb:/# ls
  abc  bin  boot  data  dev  etc  home  ifconfig  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

export
  Usage:  docker export [OPTIONS] CONTAINER
  Export a container's filesystem as a tar archive
  --help=false       Print usage
  -o, --output=      Write to a file, instead of STDOUT
  将容器的文件系统打包成tar文件
  两种方式:
  # docker export 87cb69be18bb > web.tar
  # docker export -o web.tar 87cb69be18bb
  

history
  Usage:  docker history [OPTIONS] IMAGE
  Show the history of an image
  -H, --human=true     Print sizes and dates in human readable format
  --help=false         Print usage
  --no-trunc=false     Don't truncate output
  -q, --quiet=false    Only show numeric IDs
  显示一个镜像的历史
  root@ubuntu:~# docker history ubuntu:14.04
  IMAGE       CREATED                           CREATED BY         SIZE    COMMENT
  d9560c05d6bd   2 weeks ago         /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B
  001bed837092   2 weeks ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.895 kB
  92b3f03280cc    2 weeks ago         /bin/sh -c rm -rf /var/lib/apt/lists/*          0 B
  24e6f8fb4abf     2 weeks ago         /bin/sh -c set -xe   && echo '#!/bin/sh' > /u   194.6 kB
  50ed19911a3e    2 weeks ago         /bin/sh -c #(nop) ADD file:4f5a660d3f5141588d   187.8 MB

images
  Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]
  List images
  -a, --all=false      Show all images (default hides intermediate images)
  --digests=false      Show digests
  -f, --filter=[]      Filter output based on conditions provided
  --help=false         Print usage
  --no-trunc=false     Don't truncate output
  -q, --quiet=false    Only show numeric IDs
  显示所有的镜像.
  

import
  Usage:  docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
  Import the contents from a tarball to create a filesystem image
  -c, --change=[]    Apply Dockerfile instruction to the created image
  --help=false       Print usage
  -m, --message=     Set commit message for imported image
  根据export出的tar文件创建一个镜像.
  # docker import web.tar web
DSC0004.png

  

info
  Usage:  docker info [OPTIONS]
  Display system-wide information
  --help=false       Print usage
  # docker info
  Containers: 1
  Images: 25
  Server Version: 1.9.1
  Storage Driver: aufs
  Root Dir: /var/lib/docker/aufs
  Backing Filesystem: extfs
  Dirs: 27
  Dirperm1 Supported: false
  Execution Driver: native-0.2
  Logging Driver: json-file
  Kernel Version: 3.13.0-32-generic
  Operating System: Ubuntu 14.04.1 LTS
  CPUs: 1
  Total Memory: 986.8 MiB
  Name: ubuntu
  ID: ALLP:KE4W:ITY7:WUL6:QKUG:4CGB:R6IA:2UXG:227D:K6BF:EDLL:27TX
  WARNING: No swap limit support

inspect
  Usage:  docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]
  Return low-level information on a container or image
  -f, --format=       Format the output using the given go template
  --help=false        Print usage
  -s, --size=false    Display total file sizes if the type is container
  --type=             Return JSON for specified type, (e.g image or container)
  用于查看容器的配置信息,包含容器名、环境变量、运行命令、主机配置、网络配置和数据卷配置等。
  # docker inspect 87cb69be18bb
  

kill
  Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]
  Kill a running container
  --help=false         Print usage
  -s, --signal=KILL    Signal to send to the container
  强制终止容器
  关于stop和kill的区别,docker stop命令给容器中的进程发送SIGTERM信号,默认行为是会导致容器退出,当然,容器内程序可以捕获该信号并自行处理,例如可以选择忽略。而dockerkill则是给容器的进程发送SIGKILL信号,该信号将会使容器必然退出。
  

load
  Usage:  docker load [OPTIONS]
  Load an image from a tar archive or STDIN
  --help=false       Print usage
  -i, --input=       Read from a tar archive file, instead of STDIN
  与下面的save命令相对应,将下面sava命令打包的镜像通过load命令导入。
  

login
  Usage:  docker login [OPTIONS] [SERVER]
  Register or log in to a Docker registry.
  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
  登录到自己的Docker register,需有Docker Hub的注册账号.
  

logout
  Usage:  docker logout [OPTIONS] [SERVER]
  Log out from a Docker registry.
  If no server is specified "https://index.docker.io/v1/" is the default.
  --help=false       Print usage
  从Docker register退出登录。
  

logs
  Fetch the logs of a container
  -f, --follow=false        Follow log output
  --help=false              Print usage
  --since=                  Show logs since timestamp
  -t, --timestamps=false    Show timestamps
  --tail=all                Number of lines to show from the end of the logs
  用于查看容器的日志,它将输入(出)到容器标准输入(出)的数据,作为日志输出到docker logs命令的终端上。常用于后台型容器。
  87cb69be18bb是一个数据流为输入、输出和错误和容器,如下命令则会打印该容器的所有交互日志。
  # docker logs 87cb69be18bb
  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-482346-1-1.html 上篇帖子: docker run命令详解及示例(二) 下篇帖子: docker命令详解(二)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表