博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
166.7. docker 命令
阅读量:5788 次
发布时间:2019-06-18

本文共 7771 字,大约阅读时间需要 25 分钟。

166.7.1. run

run

$ sudo docker run ubuntu:14.04 /bin/echo 'Hello world'Hello world

166.7.2. start / stop / restart

sudo docker start silly_bohrsilly_bohr$ sudo docker stop silly_bohrsilly_bohr$ sudo docker restart silly_bohrsilly_bohr

166.7.3. ps

sudo docker ps
$ sudo docker ps -lCONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES84391d1de0fc        ubuntu:14.04        /bin/echo Hello worl   31 minutes ago      Exit 0                                  romantic_ritchie

166.7.4. top

$ sudo docker psCONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES13b2a4a31455        ubuntu:14.04        /bin/bash           3 hours ago         Up 3 hours                              silly_bohr$ sudo docker top silly_bohrUID                 PID                 PPID                C                   STIME               TTY                 TIME                CMDroot                23225               22908               0                   12:17               pts/14              00:00:00            /bin/bash

166.7.5. inspect

$ sudo docker inspect silly_bohr[{    "ID": "13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a",    "Created": "2014-07-17T04:17:45.262480632Z",    "Path": "/bin/bash",    "Args": [],    "Config": {        "Hostname": "13b2a4a31455",        "Domainname": "",        "User": "",        "Memory": 0,        "MemorySwap": 0,        "CpuShares": 0,        "AttachStdin": true,        "AttachStdout": true,        "AttachStderr": true,        "PortSpecs": null,        "ExposedPorts": null,        "Tty": true,        "OpenStdin": true,        "StdinOnce": true,        "Env": [            "HOME=/",            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"        ],        "Cmd": [            "/bin/bash"        ],        "Dns": [            "8.8.8.8",            "8.8.4.4"        ],        "Image": "ubuntu",        "Volumes": null,        "VolumesFrom": "",        "WorkingDir": "",        "Entrypoint": null,        "NetworkDisabled": false,        "OnBuild": null    },    "State": {        "Running": true,        "Pid": 23225,        "ExitCode": 0,        "StartedAt": "2014-07-17T04:17:45.672269614Z",        "FinishedAt": "0001-01-01T00:00:00Z",        "Ghost": false    },    "Image": "e54ca5efa2e962582a223ca9810f7f1b62ea9b5c3975d14a5da79d3bf6020f37",    "NetworkSettings": {        "IPAddress": "172.17.0.2",        "IPPrefixLen": 16,        "Gateway": "172.17.42.1",        "Bridge": "docker0",        "PortMapping": null,        "Ports": {}    },    "ResolvConfPath": "/var/lib/docker/containers/13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a/resolv.conf",    "HostnamePath": "/var/lib/docker/containers/13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a/hostname",    "HostsPath": "/var/lib/docker/containers/13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a/hosts",    "Name": "/silly_bohr",    "Driver": "aufs",    "ExecDriver": "native-0.1",    "Volumes": {},    "VolumesRW": {},    "HostConfig": {        "Binds": null,        "ContainerIDFile": "",        "LxcConf": [],        "Privileged": false,        "PortBindings": {},        "Links": null,        "PublishAllPorts": false    }}]
$ sudo docker inspect -f '{
{ .NetworkSettings.IPAddress }}' silly_bohr

166.7.6. images

$ sudo docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZEubuntu              14.10               58faa899733f        2 weeks ago         196 MBubuntu              utopic              58faa899733f        2 weeks ago         196 MBubuntu              precise             ea7d6801c538        3 weeks ago         127.5 MBubuntu              12.04               ea7d6801c538        3 weeks ago         127.5 MBubuntu              12.10               c5881f11ded9        4 weeks ago         172.2 MBubuntu              quantal             c5881f11ded9        4 weeks ago         172.2 MBubuntu              13.04               463ff6be4238        4 weeks ago         169.4 MBubuntu              raring              463ff6be4238        4 weeks ago         169.4 MBubuntu              13.10               195eb90b5349        4 weeks ago         184.7 MBubuntu              saucy               195eb90b5349        4 weeks ago         184.7 MBubuntu              14.04               e54ca5efa2e9        4 weeks ago         276.5 MBubuntu              latest              e54ca5efa2e9        4 weeks ago         276.5 MBubuntu              trusty              e54ca5efa2e9        4 weeks ago         276.5 MBubuntu              10.04               3db9c44f4520        12 weeks ago        183 MBubuntu              lucid               3db9c44f4520        12 weeks ago        183 MB

166.7.6.1. Getting a new image

$ sudo docker pull centosPulling repository centosb7de3133ff98: Pulling dependent layers5cc9e91966f7: Pulling fs layer511136ea3c5a: Download completeef52fb1fe610: Download complete

166.7.7. logs

显示容器运行日志,用于排查异常情况

例如下面是nginx容易启动出错日志

[root@netkiller]# docker logs my-nginx-container   nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80

166.7.8. history

镜像历史纪录

# docker history centos:tomcatIMAGE               CREATED             CREATED BY                                      SIZE                COMMENT2faf9a2d2bdc        22 hours ago        /bin/sh -c #(nop)  CMD ["catalina.sh" "run"]    0 B                 8e12c1e8fd89        22 hours ago        /bin/sh -c #(nop)  EXPOSE 8080/tcp              0 B                 35158d8231c5        22 hours ago        /bin/sh -c #(nop)  VOLUME [/srv/tomcat/temp]    0 B                 4302c5c13241        22 hours ago        /bin/sh -c #(nop)  VOLUME [/srv/tomcat/work]    0 B                 53537696aa19        22 hours ago        /bin/sh -c #(nop) ADD file:ac42f23f37092b9...   298 B               be04ba27a9ae        23 hours ago        /bin/sh -c set -x   && wget -O tomcat.tar....   8.75 MB             847be662a35f        5 days ago          /bin/sh -c #(nop)  ENV TOMCAT_ASC_URL=http...   0 B                 ac6550346558        5 days ago          /bin/sh -c #(nop)  ENV TOMCAT_TGZ_URL=http...   0 B                 50c12be7ca48        5 days ago          /bin/sh -c #(nop)  ENV TOMCAT_VERSION=8.5.15    0 B                 89c44758e4ae        5 days ago          /bin/sh -c #(nop)  ENV TOMCAT_MAJOR=8           0 B                 560ad98c1b23        5 days ago          /bin/sh -c yum install -y java-1.8.0-openj...   236 MB              befeedbb7dc7        5 days ago          /bin/sh -c #(nop) WORKDIR /srv/tomcat           0 B                 c85cf394faf8        5 days ago          /bin/sh -c mkdir -p "$CATALINA_HOME"            0 B                 debf78012b2c        5 days ago          /bin/sh -c #(nop)  ENV PATH=/srv/tomcat/bi...   0 B                 ccc27f4f3bcf        5 days ago          /bin/sh -c #(nop)  ENV CATALINA_HOME=/srv/...   0 B                 8f351964d568        6 days ago          /bin/sh -c #(nop)  MAINTAINER Netkiller 
9 days ago /bin/sh -c #(nop) LABEL name=CentOS Base ... 0 B
9 days ago /bin/sh -c #(nop) ADD file:d22a9c627d1d1f3... 193 MB

原文出处:Netkiller 系列 手札

本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

你可能感兴趣的文章
ReactiveSwift源码解析(三) Signal代码的基本实现
查看>>
MVC模式利用xib文件定制collectionCell
查看>>
(六)Oracle学习笔记—— 约束
查看>>
【SQL】查询数据库中某个字段有重复值出现的信息
查看>>
mysql 行转列 列转行
查看>>
[Oracle]如何在Oracle中设置Event
查看>>
top.location.href和localtion.href有什么不同
查看>>
02-创建hibernate工程
查看>>
Open Graph Protocol(开放内容协议)
查看>>
模块化(1):基本思路
查看>>
Ubuntu18.04中配置QT5.11开发环境
查看>>
Exception的妙用
查看>>
基于浏览器的开源“管理+开发”工具,Pivotal MySQL*Web正式上线!
查看>>
JavaScript(五):变量的作用域
查看>>
知识图谱在互联网金融中的应用
查看>>
MySQL 到底能不能放到 Docker 里跑?
查看>>
wpf 自定义窗口,最大化时覆盖任务栏解决方案
查看>>
【docker】关于docker 中 镜像、容器的关系理解
查看>>
information_schema系列五(表,触发器,视图,存储过程和函数)
查看>>
瓜子二手车的谎言!
查看>>