去年中的时候玩过一段时间的 Docker,后来感觉对我没啥用就没完了。
这几天想复习下,就又开始玩了。
然后创建了一个容器:
docker container run -it --name=test centos
在里面创建一个空白文件:
touch 111
然后按 Ctrl+D 关闭容器。
再开启容器:
docker container start -a test
然后查看文件:
ls 111
会发现这个文件还在……
111
为什么会这样,我记得以前我一重启容器里面的文件都会丢失的。
附上 inspect,好像里面也没使用数据卷。
[
{
"Id": "f149e9ffd626dcffc86f3c8325abf0a7c3ddbd62e1834f4db652aae58a992dd4",
"Created": "2018-04-02T08:01:58.043257934Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-04-02T08:04:00.805282255Z",
"FinishedAt": "2018-04-02T08:05:40.914734517Z"
},
"Image": "sha256:2d194b392dd16955847a14f969b2dd319251471ffa6356be6d8f16c5bf53db9b",
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/f149e9ffd626dcffc86f3c8325abf0a7c3ddbd62e1834f4db652aae58a992dd4/resolv.conf",
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/f149e9ffd626dcffc86f3c8325abf0a7c3ddbd62e1834f4db652aae58a992dd4/hostname",
"HostsPath": "/mnt/sda1/var/lib/docker/containers/f149e9ffd626dcffc86f3c8325abf0a7c3ddbd62e1834f4db652aae58a992dd4/hosts",
"LogPath": "/mnt/sda1/var/lib/docker/containers/f149e9ffd626dcffc86f3c8325abf0a7c3ddbd62e1834f4db652aae58a992dd4/f149e9ffd626dcffc86f3c8325abf0a7c3ddbd62e1834f4db652aae58a992dd4-json.log",
"Name": "/test",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Data": {
"LowerDir": "/mnt/sda1/var/lib/docker/overlay2/3435bb5d5dbb430fcb6a9af122d0c5200de27131d5234aac3fc336c8d7070efd-init/diff:/mnt/sda1/var/lib/docker/overlay2/933b109e2e6219526f5393e8bca8dcadc22f592b41a5fcb8eadb52221eaf4838/diff",
"MergedDir": "/mnt/sda1/var/lib/docker/overlay2/3435bb5d5dbb430fcb6a9af122d0c5200de27131d5234aac3fc336c8d7070efd/merged",
"UpperDir": "/mnt/sda1/var/lib/docker/overlay2/3435bb5d5dbb430fcb6a9af122d0c5200de27131d5234aac3fc336c8d7070efd/diff",
"WorkDir": "/mnt/sda1/var/lib/docker/overlay2/3435bb5d5dbb430fcb6a9af122d0c5200de27131d5234aac3fc336c8d7070efd/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "f149e9ffd626",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "centos",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"build-date": "20180302",
"license": "GPLv2",
"name": "CentOS Base Image",
"vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "25cdd513903dff03fd8adfa4f8ebd1a61f75532eb23e493e23cb2350bda3de07",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/25cdd513903d",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "a34d1f55d960138eedeaac53eb341429a1b69444abdeec387afe999c0c96b4f9",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.