Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

163.7. docker 命令

163.7.1. run

run

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

163.7.2. start / stop / restart

sudo docker start silly_bohr
silly_bohr

$ sudo docker stop silly_bohr
silly_bohr

$ sudo docker restart silly_bohr
silly_bohr
			

163.7.3. ps

sudo docker ps
			
$ sudo docker ps -l
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
84391d1de0fc        ubuntu:14.04        /bin/echo Hello worl   31 minutes ago      Exit 0                                  romantic_ritchie
			

163.7.4. top

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
13b2a4a31455        ubuntu:14.04        /bin/bash           3 hours ago         Up 3 hours                              silly_bohr

$ sudo docker top silly_bohr
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                23225               22908               0                   12:17               pts/14              00:00:00            /bin/bash
			

163.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
			

163.7.6. images

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

163.7.6.1. Getting a new image

$ sudo docker pull centos
Pulling repository centos
b7de3133ff98: Pulling dependent layers
5cc9e91966f7: Pulling fs layer
511136ea3c5a: Download complete
ef52fb1fe610: Download complete