为什么Docker compose需要太长时间才能在Windows中构建?

时间:2019-01-21 13:15:53

标签: docker

为什么docker compose花费太长时间来开始构建映像? Docker等待约10分钟直到开始。我的图像中没有node_modules或大文件。

  • 我的网络不慢。
  • 我没有防病毒软件或防火墙。

当我添加verbose标志时,我可以看到日志:

$docker-compose --verbose -f .docker/docker-compose.my.yml build

compose.config.config.find: Using configuration files: .\.docker/docker-compose.my.yml
docker.utils.config.find_config_file: Trying paths: ['C:\\Users\\user\\.docker\\config.json', 'C:\\Users\\user\\.dockercfg']
docker.utils.config.find_config_file: Found file at path: C:\Users\user\.docker\config.json
docker.auth.load_config: Found 'auths' section
docker.auth.parse_auth: Auth data for 00000.dkr.ecr.us-east-2.amazonaws.com is absent. Client might be using a credentials store instead.
docker.auth.parse_auth: Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
docker.auth.load_config: Found 'credsStore' section
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/version HTTP/1.1" 200 560
compose.cli.command.get_client: docker-compose version 1.23.2, build 1110ad01
docker-py version: 3.6.0
CPython version: 3.6.6
OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018
compose.cli.command.get_client: Docker base_url: http+docker://localnpipe
compose.cli.command.get_client: Docker version: Platform={'Name': 'Docker Engine - Community'}, Components=[{'Name': 'Engine', 'Version': '18.09.1', 'Details': {'ApiVersion': '1.39', 'Arch': 'amd64', 'BuildTime': '2019-01-09T19:41:49.000000000+00:00', 'Experimental': 'false', 'GitCommit': '4c52b90', 'GoVersion': 'go1.10.6', 'KernelVersion': '4.9.125-linuxkit', 'MinAPIVersion': '1.12', 'Os': 'linux'}}], Version=18.09.1, ApiVersion=1.39, MinAPIVersion=1.12, GitCommit=4c52b90, GoVersion=go1.10.6, Os=linux, Arch=amd64, KernelVersion=4.9.125-linuxkit, BuildTime=2019-01-09T19:41:49.000000000+00:00
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- ('docker_default')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/networks/docker_default HTTP/1.1" 404 47
compose.service.build: Building app-www
compose.cli.verbose_proxy.proxy_callable: docker build <- (path='\\\\?\\C:\\myapp', tag='docker_app-www', rm=True, forcerm=False, pull=False, nocache=False, dockerfile='./.docker/Dockerfile-app-www', cache_from=None, labels=None, buildargs={}, network_mode=None, target=None, shmsize=None, extra_hosts=None, container_limits={'memory': None}, gzip=False, isolation=None, platform=None)

大约10分钟后,它开始构建图像。

.docker / docker-compose.my.yml

version: '3'
services:
  app-www:
    image: 00000000.dkr.ecr.us-east-2.amazonaws.com/app-www:latest
    build:
      context: ../
      dockerfile: ./.docker/Dockerfile-app-www

.docker / Dockerfile-app-www

FROM node:latest

WORKDIR /usr/src/app

COPY ./dist/myapp .

RUN npm install

EXPOSE 3000

CMD [ "npm", "start" ]

1 个答案:

答案 0 :(得分:0)

这可能是构建上下文,如文档中所述,这被发送到docker守护程序,这最终可能是一个大型传输。 来自文档(重点是我的)

https://docs.docker.com/compose/compose-file/#context

  

当提供的值是相对路径时,它将被解释为相对于Compose文件的位置。 此目录还是发送到Docker守护程序的构建上下文

判断方法是指向没有任何内容的文件夹和简化的Dockerfile,然后查看其启动速度是否更快。