软件开发架构师

docker 学习(七) docker 容器挂载

架构 63 2019-03-22 22:47

1:docker的默认存放位置:

  $ sudo su

  # cd /var/lib/docker
  # ls -F
  containers/ graph/ repositories volumes/
 
 2:把docker容器中的信息挂载到宿主机上指定的目录:
  我在项目中用到需要时,将logback的日志在容器中挂载到宿主机上,

       docker run -p 9005:9000 -it -v /home/docker/forecast/user/log:/var/log/forecast forecast/forecast.user.login /bin/bash

       
<configuration>

  <property name="APP_NAME" value="forecast.user.login" />
  <property name="LOG_PATH" value="/var/log/forecast" />
  <conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${LOG_PATH}/${APP_NAME}.log</file>
    <encoder>
      <pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
    </encoder>

 

 
 
$docker ps | less -S
[root@dpydalapp02 Downloads]# docker inspect dc617832a4df

[
    {
        "Id": "dc617832a4df88144f4d9c9dedd8e6237159983824817245c79725c034885635"                                                                             ,
        "Created": "2018-04-03T15:10:16.537716619Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForH                                                                             eap -cp '/maven/*'  -Dhttp.address=\"0.0.0.0\" -Dhttp.port=\"9000\"  play.core.s                                                                             erver.ProdServerStart"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 5366,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-04-03T15:10:16.742726688Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:738162b63cad82721ca96666d28bfa461d2fa36ea2f03fb5ae8bb89                                                                             4df781ce5",
        "ResolvConfPath": "/var/lib/docker/containers/dc617832a4df88144f4d9c9ded                                                                             d8e6237159983824817245c79725c034885635/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/dc617832a4df88144f4d9c9dedd8                                                                             e6237159983824817245c79725c034885635/hostname",
        "HostsPath": "/var/lib/docker/containers/dc617832a4df88144f4d9c9dedd8e62                                                                             37159983824817245c79725c034885635/hosts",
        "LogPath": "/var/lib/docker/containers/dc617832a4df88144f4d9c9dedd8e6237                                                                             159983824817245c79725c034885635/dc617832a4df88144f4d9c9dedd8e6237159983824817245                                                                             c79725c034885635-json.log",
        "Name": "/practical_mayer",
        "RestartCount": 0,
        "Driver": "overlay",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": [
            "65db615b68e77d7e4771fdbed5075b14e3e5c15446e59a472610f0365457f349",
            "e6bf642713ecb75e187f1b70bd0ff55956d904394e137e3e77482b2f2ed1e74f",
            "284bf463c8627e19d9277334448d570cd25443fdc6b9f7299924b1f2f11af141",
            "35e56760d67edf3e3e1748a067e30211c44235ca4a2154504bb24fad12ce0a04"
        ],
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "9000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "9003"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "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": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "overlay",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay/965099abd4a056db5ffd538d867                                                                             0472afa233cc053ec56116025ee103dc5b0dd/root",
                "MergedDir": "/var/lib/docker/overlay/7f3b3d68d1a9d143460b42ae1a                                                                             8d1600e929e459b89b3bfaa9b9c4ae21d0d769/merged",
                "UpperDir": "/var/lib/docker/overlay/7f3b3d68d1a9d143460b42ae1a8                                                                             d1600e929e459b89b3bfaa9b9c4ae21d0d769/upper",
                "WorkDir": "/var/lib/docker/overlay/7f3b3d68d1a9d143460b42ae1a8d                                                                             1600e929e459b89b3bfaa9b9c4ae21d0d769/work"
            }
        },
        "Mounts": [],
        "Config": {
            "Hostname": "dc617832a4df",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "9000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/b                                                                             in:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk/jre",
                "JAVA_VERSION=8u151",
                "JAVA_ALPINE_VERSION=8.151.12-r0"
            ],
            "Cmd": null,
            "ArgsEscaped": true,
            "Image": "forecast/forecast.user.login",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/bin/sh",
                "-c",
                "java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimit                                                                             ForHeap -cp '/maven/*'  -Dhttp.address=\"0.0.0.0\" -Dhttp.port=\"9000\"  play.co                                                                             re.server.ProdServerStart"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "22c620d718adfea09dac0eecf4257e7a1135ede6993a4ca413fd1e                                                                             cdfa3bbef4",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "9000/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "9003"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/22c620d718ad",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "f4cb19dc49d934cbe0fe63a1a4d1a3e6153d212d26cd8c0c583f8                                                                             d8aec97e2ab",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.4",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:04",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "ed31251886bbeda09a512bbddcd2481372b183bd610abf                                                                             3a38326264165a4056",
                    "EndpointID": "f4cb19dc49d934cbe0fe63a1a4d1a3e6153d212d26cd8                                                                             c0c583f8d8aec97e2ab",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.4",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:04"
                }
            }
        }
    }
]

 

 
 
文章评论