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

[经验分享] docker 命令

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-9 10:45:35 | 显示全部楼层 |阅读模式
学了一段时间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 [options "o">] 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">] [user/ "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 [OPTIONS] [SERVER]
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 [options "o">] [name]
列出本地所有镜像。其中 [name] 对镜像名称进行关键词查询。
-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>] 列出满足
exited=<int> 条件的容器;
-l 仅列出最新创建的一个容器;
--no-trunc 显示完整的容器ID;
-n=4 列出最近创建的4个容器;
-q 仅列出容器ID;
-s 显示容器大小。
9. docker rmi
docker rmi [options "o">] <image>  "o">[image...]
docker rmi nginx:latest postgres:latest python:latest
从本地移除一个或多个指定的镜像。
-f 强行移除该镜像,即使其正被使用;
--no-prune 不移除该镜像的过程镜像,默认移除。
10. docker rm
docker rm [options "o">] <container>  "o">[container...]
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">[options] <image>
查看指定镜像的创建历史。
--no-trunc 显示完整的提交记录;
-q 仅列出提交记录ID。
12. docker start|stop|restart
docker start|stop "p">|restart [options "o">] <container>  "o">[container...]
启动、停止和重启一个或多个指定容器。
-a 待完成
-i 启动一个容器并进入交互模式;
-t 10 停止或者重启容器的超时时间(秒),超时后系统将杀死进程。
13. docker kill
docker kill  "o">[options "o">] <container>  "o">[container...]
杀死一个或多个指定容器进程。
-s "KILL" 自定义发送至容器的信号。
14. docker events
docker events [options "o">]
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 [options]
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">[repository[:tag "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 options]
查看一个正在运行容器进程,支持 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 [options "o">] <image>[:tag "o">] [repository/ "o">][username/]name "o">[:tag]
标记本地镜像,将其归入某一仓库。
-f 覆盖已有标记。
24. docker push
docker push name[:tag "o">]
docker push laozhu/nginx:latest
将镜像推送至远程仓库,默认为 Docker Hub 。
25. docker logs
docker logs [options "o">] <container>
docker logs -f -t --tail= "s2">"10" insane_babbage
获取容器运行时的输出日志。
-f 跟踪容器日志的最近更新;
-t 显示容器日志的时间戳;
--tail="10" 仅列出最新10条容器日志。
26. docker run
docker run [options "o">] <image> [ "nb">command]  "o">[arg...]
启动一个容器,在其中运行指定命令。
-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



运维网声明 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-255294-1-1.html 上篇帖子: docker桥接网络原理图分享和pipework简单配置 下篇帖子: Docker搭建本地私有仓库
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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