Volume
提供獨立於容器以外的持久化存儲html
運行時加入 -v 指定保存目錄
運行後保存容器中的某個目錄下的文件到本地服務器mysql
運行
docker run -d -p 8080:80 -v /usr/share/nginx/html hub.c.163.com/library/nginxlinux
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1de38756a14 hub.c.163.com/library/nginx "nginx -g 'daemon of…" 7 minutes ago Up 7 minutes 0.0.0.0:8080->80/tcp inspiring_snyder
c71cf6554cc0 hub.c.163.com/library/mysql:latest "docker-entrypoint.s…" 6 hours ago Up 6 hours 0.0.0.0:3306->3306/tcp kind_stallmannginx
檢查鏡像
docker inspect b1de38756a14
[
{
"Id": "b1de38756a14112876e741be54f748b3574ea28e313e8804b6c37e4a2e66d7f7",
"Created": "2018-06-10T16:40:29.32542017Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 72359,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-06-10T16:40:29.767102986Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:46102226f2fd547f5bbabfcd3dac62cd0d3b7cc33a37a40dae38e088fbb70a38",
"ResolvConfPath": "/var/lib/docker/containers/b1de38756a14112876e741be54f748b3574ea28e313e8804b6c37e4a2e66d7f7/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/b1de38756a14112876e741be54f748b3574ea28e313e8804b6c37e4a2e66d7f7/hostname",
"HostsPath": "/var/lib/docker/containers/b1de38756a14112876e741be54f748b3574ea28e313e8804b6c37e4a2e66d7f7/hosts",
"LogPath": "/var/lib/docker/containers/b1de38756a14112876e741be54f748b3574ea28e313e8804b6c37e4a2e66d7f7/b1de38756a14112876e741be54f748b3574ea28e313e8804b6c37e4a2e66d7f7-json.log",
"Name": "/inspiring_snyder",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
]
},
"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": "/var/lib/docker/overlay2/286c66161a6c3a177443531f6b2498dfc758a0cdf968fc80e9b55ee4dd2ae805-init/diff:/var/lib/docker/overlay2/7ccd9884a6415246657126945aaafe0ca5dc7f441008621063bcb864a1103a4a/diff:/var/lib/docker/overlay2/514740a8bee43934b08595850a04e851081511e29784cc15864fc8a895720126/diff:/var/lib/docker/overlay2/099aee435090164e3800975f5e898741bd2d4a9fb612bf0d161c36ccce71ffdc/diff",
"MergedDir": "/var/lib/docker/overlay2/286c66161a6c3a177443531f6b2498dfc758a0cdf968fc80e9b55ee4dd2ae805/merged",
"UpperDir": "/var/lib/docker/overlay2/286c66161a6c3a177443531f6b2498dfc758a0cdf968fc80e9b55ee4dd2ae805/diff",
"WorkDir": "/var/lib/docker/overlay2/286c66161a6c3a177443531f6b2498dfc758a0cdf968fc80e9b55ee4dd2ae805/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "volume",
"Name": "bfaea3344c46ea20f456ba21404c3a61495729b0ca882d2a46932f3be0127bcc",
"Source": "/var/lib/docker/volumes/bfaea3344c46ea20f456ba21404c3a61495729b0ca882d2a46932f3be0127bcc/_data",
"Destination": "/usr/share/nginx/html",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "b1de38756a14",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.13.0-1~stretch",
"NJS_VERSION=1.13.0.0.1.10-1~stretch"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"ArgsEscaped": true,
"Image": "hub.c.163.com/library/nginx",
"Volumes": {
"/usr/share/nginx/html": {}
},
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {},
"StopSignal": "SIGQUIT"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "e7a83bae8e08e242c713691975d0357d8ce730c6ed5316cf9b9da34d8b663608",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
]
},
"SandboxKey": "/var/run/docker/netns/e7a83bae8e08",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "dc8e990f9d404aeacd60296996effc54dc5c823f4b680901af18d7c6dff8da5d",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "e8e4805fcf95e9463bcb3a5adad4de6f9f462f564578873537ce8dfedc419759",
"EndpointID": "dc8e990f9d404aeacd60296996effc54dc5c823f4b680901af18d7c6dff8da5d",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]sql
cd /var/lib/docker/volumes/bfaea3344c46ea20f456ba21404c3a61495729b0ca882d2a46932f3be0127bcc/_data
vim index.htmldocker
修改後的內容,不拉不拉···json
進入鏡像內部目錄
docker exec -it b1de38756a14 /bin/bashvim
cd /usr/share/nginx/html
ls
50x.html index.htmlbash
cat index.html
與服務器中的index.html是一致的
即這裏的文件對應的就是/var/lib/docker/volumes/bfaea3344c46ea20f456ba21404c3a61495729b0ca882d2a46932f3be0127bcc/_data目錄下的文件服務器
本地目錄掛載到鏡像中
docker run -d -p 80:80 -v $PWD/html:/var/www/html nginx
說明:$PWD 指向當前目錄
docker run --volumes-from ...