13

While building new Docker images within Docker Machine environment I noticed that docker-compose build app command freezes for 10-12 minutes before it starts actual build process:

$ docker-compose build app Building app ... 10 minutes ... Step 1/10 : FROM ruby:2.4.1 ---> e7ca4a0b5b6d ... 

I tried to use --verbose parameter to make it more descriptive, but that didn't actually help:

$ 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 

Is there any way to understand, what is going and how to make build process faster?

6
  • When it is waiting, try hitting CTRL + C and see if you get a exception trace? Commented Sep 23, 2017 at 6:25
  • @TarunLalwani no, I got nothing, just silent halt. Commented Sep 23, 2017 at 9:25
  • What is the output of du -sh . in the compose folder? Commented Sep 23, 2017 at 10:42
  • @TarunLalwani 228M .. Commented Sep 23, 2017 at 13:14
  • 1
    Yes and that may be what is happening here. You should only send what is needed in the image and nothing else Commented Sep 23, 2017 at 18:42

1 Answer 1

15

Big thanks to Tarun Lalwani I learned about Docker context.

The build context is a set of files located at a specified location. Is my (the most trivial) case location is simply . — project directory. The first thing a build process does is copy entire context to the daemon. Since I'm using Docker Machine to deploy my containers Docker daemon sits on the remote host, which cause the entire project folder being send to the server via internet.

With all unnecessary for production folders, such as .git, tmp, total size was way almost 200 MB:

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

By using simple .dockerignore rules I was able to reduce it dramatically:

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

Lesson learned — use .dockerignore.

Detailed explanation can be found at Dockerfile reference.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.