【问题标题】:How to make Docker Compose builds faster?如何让 Docker Compose 构建速度更快?
【发布时间】:2017-09-23 02:00:12
【问题描述】:

在 Docker Machine 环境中构建新的 Docker 映像时,我注意到 docker-compose build app 命令在开始实际构建过程之前会冻结 10-12 分钟:

$ docker-compose build app
Building app

... 10 minutes ...

Step 1/10 : FROM ruby:2.4.1
 ---> e7ca4a0b5b6d
...

我尝试使用--verbose 参数使其更具描述性,但这实际上并没有帮助:

$ docker-compose --verbose build
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.auth.find_config_file: Trying paths: ['/Users/vtambourine/.docker/config.json', '/Users/vtambourine/.dockercfg']
docker.auth.find_config_file: Found file at path: /Users/vtambourine/.docker/config.json
docker.auth.load_config: Couldn't find 'auths' or 'HttpHeaders' sections
docker.auth.parse_auth: Auth data for {0} is absent. Client might be using a credentials store instead.
compose.cli.command.get_client: docker-compose version 1.14.0, build c7bdf9e
docker-py version: 2.3.0
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
compose.cli.command.get_client: Docker base_url: https://146.185.007.007:2376
compose.cli.command.get_client: Docker version: KernelVersion=4.9.0-3-amd64, Arch=amd64, BuildTime=2017-09-05T19:58:57.182575033+00:00, ApiVersion=1.30, Version=17.06.2-ce, MinAPIVersion=1.12, GitCommit=cec0b72, Os=linux, GoVersion=go1.8.3
compose.project.build: db uses an image, skipping
compose.service.build: Building app
compose.cli.verbose_proxy.proxy_callable: docker build <- (pull=False, cache_from=None, stream=True, nocache=False, labels=None, tag='aerostat:app', buildargs={}, forcerm=False, rm=True, path='/Users/vtambourine/Code/aerostat', dockerfile='containers/development/Dockerfile')
docker.api.build._set_auth_headers: Looking for auth config
docker.api.build._set_auth_headers: Sending auth config (u'auths')
compose.cli.verbose_proxy.proxy_callable: docker build -> <generator object _stream_helper at 0x10b61f230>

... 10 minutes ...

Step 1/10 : FROM ruby:2.4.1
---> e7ca4a0b5b6d

有什么方法可以理解,发生了什么以及如何使构建过程更快?

【问题讨论】:

  • 当它等待时,尝试按 CTRL + C 看看是否有异常跟踪?
  • @TarunLalwani 不,我什么也没得到,只是静默。
  • compose文件夹中du -sh .的输出是什么?
  • @TarunLalwani 228M ..
  • 是的,这可能就是这里发生的事情。您应该只发送图像中需要的内容,不要发送其他内容

标签: docker docker-compose docker-machine


【解决方案1】:

非常感谢 Tarun Lalwani,我了解了 Docker 上下文。

构建上下文是位于指定位置的一组文件。我的(最琐碎的)案例位置是否只是. - 项目目录。构建过程所做的第一件事是将整个上下文复制到守护进程。由于我使用 Docker Machine 部署我的容器 Docker 守护程序位于远程主机上,这导致整个项目文件夹通过互联网发送到服务器。

包含所有不必要的生产文件夹,例如.gittmp,总大小接近 200 MB:

$ docker build -t my-app -f containers/production/Dockerfile .
Sending build context to Docker daemon  187.9MB

通过使用简单的.dockerignore 规则,我能够显着减少它:

$ docker build -t my-app -f containers/production/Dockerfile .
Sending build context to Docker daemon  151kB

经验教训——使用.dockerignore

详细解释可以在Dockerfile reference找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 2013-06-10
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多