我的docker-compose正在从另一个文件夹中获取文件,而不是从我运行该命令的位置

时间:2016-11-10 14:05:19

标签: docker docker-compose meanjs

进入容器后,由于某种原因它从这个位置读取代码,我不知道如何以及从何处加载代码: /家/指

但是所需的(真实代码)内容正在这里上传:
的/ opt / LTG /

这是我的docker-compose文件内容,我认为问题在于VOLUMES参数。

当我尝试进入容器内部并查找html视图时,结果显示它与我之前使用过的另一个文件夹相关联。

我使用https://github.com/meanjs/mean meanjs来构建我的项目,所以我使用他们的docker文件,所以他们使用docker的方式。

version: '2'
services:
  web:
    restart: always
    build: .
    container_name: ltg
    ports:
     - "3000:3000"
     - "5858:5858"
     - "8080:8080"
     - "35729:35729"
    environment:
     - NODE_ENV=development
     - DB_1_PORT_27017_TCP_ADDR=db
    depends_on:
     - db
    volumes_from:
     - web-data
  web-data:
    build: .
    entrypoint: /bin/true
    volumes:
     - ./:/opt/ltg
     - /opt/ltg/node_modules
     - /opt/ltg/public
     - /opt/ltg/uploads
  db:
    image: mongo:3.2
    restart: always
    ports:
     - "27017:27017"
    volumes_from:
      - db-data
  db-data:
    image: mongo:3.2
    volumes:
      - /data/db
      - /var/lib/mongodb
      - /var/log/mongodb
    entrypoint: /bin/true

Dockerfile。 (我认为这个问题在这里),但即使我将/ home / mean更改为/ opt / ltg,它似乎也无法正常工作。

 FROM node:0.12

# Install gem sass for  grunt-contrib-sass
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get install -y ruby
RUN gem install sass

WORKDIR /opt/ltg

# Install Mean.JS Prerequisites
RUN npm install -g grunt-cli
RUN npm install -g bower

# Install Mean.JS packages
ADD package.json /opt/ltg/package.json
RUN npm install

# Manually trigger bower. Why doesnt this work via npm install?
ADD .bowerrc /opt/ltg/.bowerrc
ADD bower.json /opt/ltg/bower.json
RUN bower install --config.interactive=false --allow-root

# Make everything available for start
ADD . /opt/ltg

# Set development environment as default
ENV NODE_ENV development

# Port 3000 for server
# Port 35729 for livereload
EXPOSE 3000 35729
CMD ["grunt"]

当我进入docker机器时,我可以看到它里面有代码,但我不知道为什么它从另一个地方挑选它。

inside docker container

Docker检查

± docker inspect e8a6e44e7a78
[
    {
        "Id": "e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51",
        "Created": "2016-11-11T21:51:59.315251772Z",
        "Path": "grunt",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 6521,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-11-11T21:52:00.23437815Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:8b93f26cc274bf69cd9e2c24161ef8b1a09acc958fb94027838897b0bf860d4e",
        "ResolvConfPath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/hostname",
        "HostsPath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/hosts",
        "LogPath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51-json.log",
        "Name": "/ltg",
        "RestartCount": 0,
        "Driver": "overlay2",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "ltg_default",
            "PortBindings": {
                "3000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "3000"
                    }
                ],
                "35729/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "35729"
                    }
                ],
                "5858/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "5858"
                    }
                ],
                "8080/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8080"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "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,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "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": "overlay2",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e-init/diff:/var/lib/docker/overlay2/ba7c11c0aac2c7c97c6f0d2876ed600b3724c0cabaa40d58f579db4573b4e8ed/diff:/var/lib/docker/overlay2/807a7a90f77a22724db8e54a57ad91b1ef1f2b06e88ad42524042f46c9da39d7/diff:/var/lib/docker/overlay2/14cbc06a270e4fddd6287d8f90cb2e885b1387be4dc0b79678f866b59e12063c/diff:/var/lib/docker/overlay2/369cc5f5a0ba13fe12e2d42d35f78f1bfcfdd80c0a0d64f0a22e9a6a036149aa/diff:/var/lib/docker/overlay2/854bf8973559090707e5d89c820ae70539392f9970b1646fb8178ff401ae3c5b/diff:/var/lib/docker/overlay2/d6db404071f5f6741dc2555bb87142f0fbfb511a7c70f03085ddcae108bbf5ae/diff:/var/lib/docker/overlay2/869b67fd3eb7e0f4856433eddd0dd1604170bf8d70c97070a4c1866c46a82024/diff:/var/lib/docker/overlay2/2fa6daceeb2d0b83fcb08a8b46d8894f182c8e2bb206e87d5af0e7fc73452c29/diff:/var/lib/docker/overlay2/b61d40c66620b7088c0ba4d37e776eef9a40ece901cf2e1ead26c8cbde3ebfe5/diff:/var/lib/docker/overlay2/c2470f33522483b8c7f2651e24ebee088f27fcdac2b8b93e9183e5d022ebc883/diff:/var/lib/docker/overlay2/a48f7cee20a989218f7eb20a8d6bc0b31a3c3e4e968a0a5271a13297a2b37b89/diff:/var/lib/docker/overlay2/e69b54cfe8a5a5c5cacf5e77603bd6e24695dba569c6bf5b0c9788f4b008c22c/diff:/var/lib/docker/overlay2/2dd3ff884efc421fed1e548a4b0c6c633dd59b62c077811718ed5b7bf0fde7fd/diff:/var/lib/docker/overlay2/b5c1cc249ce2798dbfff752cd2f4878bc7777951cd11013ceecb44d0eb933aff/diff:/var/lib/docker/overlay2/e9006ecc5d8f18345f402c96e9149b2b0dd6689d1d476b896049237ea41de404/diff:/var/lib/docker/overlay2/2debe0ee8462910da0e18bbd9ac6c1c902b157f7b15b23f866add9163d008aa3/diff:/var/lib/docker/overlay2/d0bc087a8ea87721eb7feb31dd7999e6e9755e991b88f4e728fc93669ee8590e/diff:/var/lib/docker/overlay2/76deca402cfba36204612590cb0de02a5ff8fab6d6053263af0a81e6da79fb78/diff:/var/lib/docker/overlay2/737638f3bceb8c85288c3477da936e3b523dbabd787e72989e639df24195329b/diff",
                "MergedDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e/merged",
                "UpperDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e/diff",
                "WorkDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e/work"
            }
        },
        "Mounts": [],
        "Config": {
            "Hostname": "e8a6e44e7a78",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3000/tcp": {},
                "35729/tcp": {},
                "5858/tcp": {},
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "NODE_ENV=development",
                "DB_1_PORT_27017_TCP_ADDR=db",
                "no_proxy=*.local, 169.254/16",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NODE_VERSION=0.12.17"
            ],
            "Cmd": [
                "grunt"
            ],
            "Image": "ltg_web",
            "Volumes": null,
            "WorkingDir": "/home/mean",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "7a3cb3d6a460fc5a975aafe44279ec835e5bb92141ae537ac0fd044c94243abe",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "ltg",
                "com.docker.compose.service": "web",
                "com.docker.compose.version": "1.9.0-rc2"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "a1b78ae1a7e589977a6f23e1fe1274bb494324b7ce7b9f99d16bb7e78678f721",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3000/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "3000"
                    }
                ],
                "35729/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "35729"
                    }
                ],
                "5858/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5858"
                    }
                ],
                "8080/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8080"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/a1b78ae1a7e5",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "ltg_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "web",
                        "e8a6e44e7a78"
                    ],
                    "NetworkID": "cdde7613dceaf26fac855d124172f3b0606ab685585a69974e87c4f4ed4fed6c",
                    "EndpointID": "b4618fb75407538391035f610281374407c9b9a513028ccf981a390d689dbe93",
                    "Gateway": "172.19.0.1",
                    "IPAddress": "172.19.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:13:00:03"
                }
            }
        }
    }
]

我不会低估这个/ home /意味着进入变量

    "WorkingDir": "/home/mean",

1 个答案:

答案 0 :(得分:0)

我认为我们需要更多信息才能正确回答这个问题。所以我会假设一些事情。

  1. opt/ltg目录指向docker-compose.yml所在的目录,而不是您运行docker-compose的目录。通常是同一个目录。尝试修改我的docker-compose.yml就像添加注释一样。转到带有docker exec的容器并检查docker-compose.yml的内容,添加的注释应该在那里。

  2. 我认为您的html文件也会转到/opt/ltg/public,因为您也将其声明为卷。 Docker将在您的主机中创建另一个与当前目录不同的目录。使用docker inspect查看它们的位置。如果您运行docker-compose down -v,您应该删除这些文件。

  3. 除非您确实需要,否则不要重叠卷。我建议改用此docker-compose.yml:

  4. 搬运工-compose.yml

    version: '2'
    services:
      web:
        restart: always
        build: .
        container_name: ltg
        ports:
         - "3000:3000"
         - "5858:5858"
         - "8080:8080"
         - "35729:35729"
        environment:
         - NODE_ENV=development
         - DB_1_PORT_27017_TCP_ADDR=db
        depends_on:
         - db
        volumes_from:
         - web-data
      web-data:
        build: .
        entrypoint: /bin/true
        volumes:
         - ./:/opt/ltg
      db:
        image: mongo:3.2
        restart: always
        ports:
         - "27017:27017"
        volumes_from:
          - db-data
      db-data:
        image: mongo:3.2
        volumes:
          - /data/db
          - /var/lib/mongodb
          - /var/log/mongodb
        entrypoint: /bin/true
    

    问候