您的位置:首页 > 运维架构 > Docker

docker容器的基本操作

2016-01-22 00:00 866 查看
查看创建了那些容器
显示所有
root@eddy:~/ubuntu-precise# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
6c232c270b78        ubuntu-base         "/bin/bash"            31 seconds ago      Exited (0) 15 seconds ago                       trusting_borg
d1f43662f2db        ubuntu-base         "echo 'hello world'"   2 minutes ago       Exited (0) 2 minutes ago                        condescending_swirles
e4f98dde605b        ubuntu-base         "/bin/bash"            6 minutes ago       Exited (0) 3 minutes ago

显示最近的一个容器
root@eddy:~/ubuntu-precise# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                      PORTS               NAMES
6c232c270b78        ubuntu-base         "/bin/bash"         About a minute ago   Exited (0) 44 seconds ago

不加参数显示正在运行的容器

查看容器配置信息
root@eddy:~/ubuntu-precise# docker inspect 6c232c270b78
[
{
"Id": "6c232c270b786102e77b1000ee09bf4babb5c2200becfb1764fdd0e57e42987a",
"Created": "2016-01-21T15:16:18.664486126Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2016-01-21T15:16:19.032612469Z",
"FinishedAt":&nbs
7fe0
p;"2016-01-21T15:16:34.05993231Z"
},
"Image": "a92d7a8df1bca21b8e5545820c4028bb472004a1f9d2689fc61ed4897fec906a",
"ResolvConfPath": "/var/lib/docker/containers/6c232c270b786102e77b1000ee09bf4babb5c2200becfb1764fdd0e57e42987a/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/6c232c270b786102e77b1000ee09bf4babb5c2200becfb1764fdd0e57e42987a/hostname",
"HostsPath": "/var/lib/docker/containers/6c232c270b786102e77b1000ee09bf4babb5c2200becfb1764fdd0e57e42987a/hosts",
"LogPath": "/var/lib/docker/containers/6c232c270b786102e77b1000ee09bf4babb5c2200becfb1764fdd0e57e42987a/6c232c270b786102e77b1000ee09bf4babb5c2200becfb1764fdd0e57e42987a-json.log",
"Name": "/trusting_borg",
"RestartCount": 0,
"Driver": "aufs",
"ExecDriver": "native-0.2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LxcConf": [],
"Memory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"KernelMemory": 0,
"CpuShares": 0,
"CpuPeriod": 0,
"CpusetCpus": "",
"CpusetMems": "",
"CpuQuota": 0,
"BlkioWeight": 0,
"OomKillDisable": false,
"MemorySwappiness": -1,
"Privileged": false,
"PortBindings": {},
"Links": null,
"PublishAllPorts": false,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"VolumesFrom": null,
"Devices": [],
"NetworkMode": "default",
"IpcMode": "",
"PidMode": "",
"UTSMode": "",
"CapAdd": null,
"CapDrop": null,
"GroupAdd": null,
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"SecurityOpt": null,
"ReadonlyRootfs": false,
"Ulimits": null,
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"CgroupParent": "",
"ConsoleSize": [
0,
0
],
"VolumeDriver": ""
},
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"Mounts": [],
"Config": {
"Hostname": "6c232c270b78",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": null,
"Cmd": [
"/bin/bash"
],
"Image": "ubuntu-base",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": null,
"SandboxKey": "",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": ""
}
}
}
}
]
docker自定义容器名
root@eddy:~/ubuntu-precise# docker run --name=contain01 -t -i ubuntu-base /bin/bash

root@eddy:~/ubuntu-precise# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
9b85185b9b9e        ubuntu-base         "/bin/bash"         5 seconds ago       Exited (0) 1 seconds ago                       contain01

重启启动停止的容器
root@eddy:~/ubuntu-precise# docker start -i contain01
删除容器(已经停止的容器)
root@eddy:~/ubuntu-precise# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                     PORTS               NAMES
9b85185b9b9e        ubuntu-base         "/bin/bash"            2 minutes ago       Exited (0) 2 seconds ago                       contain01
6c232c270b78        ubuntu-base         "/bin/bash"            6 minutes ago       Exited (0) 6 minutes ago                       trusting_borg
d1f43662f2db        ubuntu-base         "echo 'hello world'"   8 minutes ago       Exited (0) 8 minutes ago                       condescending_swirles
e4f98dde605b        ubuntu-base         "/bin/bash"            12 minutes ago      Exited (0) 9 minutes ago                       ecstatic_mahavira
root@eddy:~/ubuntu-precise# docker rm e4f98dde605b
e4f98dde605b
root@eddy:~/ubuntu-precise# docker ps -a
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                      PORTS               NAMES
9b85185b9b9e        ubuntu-base         "/bin/bash"            3 minutes ago       Exited (0) 39 seconds ago                       contain01
6c232c270b78        ubuntu-base         "/bin/bash"            6 minutes ago       Exited (0) 6 minutes ago                        trusting_borg
d1f43662f2db        ubuntu-base         "echo 'hello world'"   8 minutes ago       Exited (0) 8 minutes ago                        condescending_swirles

总结
docker run -i -t
docker ps -a -l
docker inspect
docker start -i
docker rm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: