为什么 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:Usersuser.dockerconfig.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" ]

它可能是构建上下文,如文档中所述,它被发送到 docker 守护进程,最终可能是一次大型传输。来自文档(强调我的)

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

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

判断方法是指向一个没有任何内容的文件夹和一个简化的 Dockerfile,看看它是否启动得更快。

最新更新