1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
| docker run -it -v 主机目录:容器内目录
[root@centos7 ~]# cd /home [root@centos7 home]# ls name sun.java test.java
# 使用命令挂载 [root@centos7 home]# docker run -it -v /home/ceshi:/home centos /bin/bash [root@d7bd1e6e693f /]# cd /home [root@d7bd1e6e693f home]# ls [root@d7bd1e6e693f home]# [root@centos7 home]# [root@centos7 home]# ls ceshi name sun.java test.java [root@centos7 home]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d7bd1e6e693f centos "/bin/bash" 3 minutes ago Up 3 minutes flamboyant_gates 6868cb5454ee tomcat "catalina.sh run" 17 hours ago Up 17 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp hardcore_ardinghelli
# 查看相关信息 [root@centos7 home]# docker inspect d7bd1e6e693f [ { "Id": "d7bd1e6e693fc22f3db7734798b63c2eade1a7154a84b354661d3c546bc7718a", "Created": "2021-06-21T01:08:46.218734547Z", "Path": "/bin/bash", "Args": [], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 4149, "ExitCode": 0, "Error": "", "StartedAt": "2021-06-21T01:08:48.057350529Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55", "ResolvConfPath": "/var/lib/docker/containers/d7bd1e6e693fc22f3db7734798b63c2eade1a7154a84b354661d3c546bc7718a/resolv.conf", "HostnamePath": "/var/lib/docker/containers/d7bd1e6e693fc22f3db7734798b63c2eade1a7154a84b354661d3c546bc7718a/hostname", "HostsPath": "/var/lib/docker/containers/d7bd1e6e693fc22f3db7734798b63c2eade1a7154a84b354661d3c546bc7718a/hosts", "LogPath": "/var/lib/docker/containers/d7bd1e6e693fc22f3db7734798b63c2eade1a7154a84b354661d3c546bc7718a/d7bd1e6e693fc22f3db7734798b63c2eade1a7154a84b354661d3c546bc7718a-json.log", "Name": "/flamboyant_gates", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": [ "/home/ceshi:/home" ], "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "CgroupnsMode": "host", "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": null, "GroupAdd": null, "IpcMode": "private", "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, "DeviceRequests": null, "KernelMemory": 0, "KernelMemoryTCP": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": false, "PidsLimit": null, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0, "MaskedPaths": [ "/proc/asound", "/proc/acpi", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/timer_list", "/proc/timer_stats", "/proc/sched_debug", "/proc/scsi", "/sys/firmware" ], "ReadonlyPaths": [ "/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger" ] }, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/711e9edb5aeec3c26ec8889f1c0879e6454012a527c73ec12d3a27a6f28298e0-init/diff:/var/lib/docker/overlay2/dbe0863967eda16db79356c5aa892895ef73d0afee2ecec4b52c209393f16103/diff", "MergedDir": "/var/lib/docker/overlay2/711e9edb5aeec3c26ec8889f1c0879e6454012a527c73ec12d3a27a6f28298e0/merged", "UpperDir": "/var/lib/docker/overlay2/711e9edb5aeec3c26ec8889f1c0879e6454012a527c73ec12d3a27a6f28298e0/diff", "WorkDir": "/var/lib/docker/overlay2/711e9edb5aeec3c26ec8889f1c0879e6454012a527c73ec12d3a27a6f28298e0/work" }, "Name": "overlay2" }, # 挂载 "Mounts": [ { "Type": "bind", "Source": "/home/ceshi", "Destination": "/home", "Mode": "", "RW": true, "Propagation": "rprivate" } ], "Config": { "Hostname": "d7bd1e6e693f", "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" ], "Image": "centos", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.build-date": "20201204", "org.label-schema.license": "GPLv2", "org.label-schema.name": "CentOS Base Image", "org.label-schema.schema-version": "1.0", "org.label-schema.vendor": "CentOS" } }, "NetworkSettings": { "Bridge": "", "SandboxID": "5dde2a555d6ebe590a4cab2cc07ccac80e49289b0565d8c15a04b99ef5853765", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/5dde2a555d6e", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "608816e6eca9c267896e7254e97246a02ecbcb955148eddfe96e2dc6fb53856f", "Gateway": "172.17.0.1", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.3", "IPPrefixLen": 16, "IPv6Gateway": "", "MacAddress": "02:42:ac:11:00:03", "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "2dc7231034028aab340034b6ff968fc0b71a79f04e5db48c916ac2b79d48476e", "EndpointID": "608816e6eca9c267896e7254e97246a02ecbcb955148eddfe96e2dc6fb53856f", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.3", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:03", "DriverOpts": null } } } } ] [root@centos7 home]#
|