Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The build and copy steps take an absurdly long time #30414

Closed
krainboltgreene opened this issue Jan 24, 2017 · 12 comments
Closed

The build and copy steps take an absurdly long time #30414

krainboltgreene opened this issue Jan 24, 2017 · 12 comments

Comments

@krainboltgreene
Copy link

Description

While building my containers with docker-compose build I'm encountering absurdly long build times. The Building {{container}} step takes upwards of 2 minutes and a simple COPY {{file}} {{file}} can take upwards of 1 minute.

Steps to reproduce the issue:

  1. Run docker-compose build
  2. Watch

Describe the results you received:

It took a long time on very simple operations.

Describe the results you expected:

It doesn't take a long time.

Additional information you deem important (e.g. issue happens only occasionally):

I'm building containers locally, on a Mac, via Docker Toolset.

Output of docker version:

$ docker-machine ssh wolf-machine docker version
Client:
 Version:      1.13.0
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Wed Jan 18 16:20:26 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.0
 API version:  1.25 (minimum version 1.12)
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Wed Jan 18 16:20:26 2017
 OS/Arch:      linux/amd64
 Experimental: false

Output of docker info:

$ docker-machine ssh wolf-machine docker info
Containers: 6
 Running: 5
 Paused: 0
 Stopped: 1
Images: 32
Server Version: 1.13.0
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 86
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 03e5862ec0d8d3b3f750e19fca3ee367e13c090e
runc version: 2f7393a47307a16f8cee44a37b262e8b81021e3e
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.4.43-boot2docker
Operating System: Boot2Docker 1.13.0 (TCL 7.2); HEAD : 5b8d9cb - Wed Jan 18 18:50:40 UTC 2017
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.858 GiB
Name: wolf-machine
ID: 6ZPY:NZFB:4FGB:SCNM:5N7S:7OOH:7WNH:7DGW:Z2YY:BMID:MLTD:DHTH
Docker Root Dir: /mnt/sda1/var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 72
 Goroutines: 76
 System Time: 2017-01-24T17:40:04.496970561Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
 provider=virtualbox
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):
screen shot 2017-01-24 at 9 41 22 am

@krainboltgreene
Copy link
Author

My host machine is beefy as all heck, so I doubt it's that:
screen shot 2017-01-24 at 9 43 19 am

@krainboltgreene
Copy link
Author

Also, I'm using NFS via docker-machine-nfs: https://github.com/adlogix/docker-machine-nfs

@thaJeztah
Copy link
Member

The actual build is executed on the daemon. When doing a build, the "build context" is therefore sent to the daemon as a tar archive; the time to start the build therefore dependent on the size of your build context (the directory from which you're starting the build); can you tell how big the context is?

@krainboltgreene
Copy link
Author

@thaJeztah If you can give me the commands to do it I'll get you what you need. I love docker and want to see if I can fix this for my team.

@thaJeztah
Copy link
Member

@krainboltgreene just the size, and number of files that are in the directory that your Dockerfile is in (right-click get info in the Finder should do)

@krainboltgreene
Copy link
Author

krainboltgreene commented Jan 24, 2017

@thaJeztah

$ du -hs .
1.2G	.

@krainboltgreene
Copy link
Author

krainboltgreene commented Jan 24, 2017

Okay, so I did some spring cleaning and I'm down to 622MB, 420 of which are from {{container}}/node_modules/.

If my project tree looks like this:

| tree -L 2
.
├── FAQ.md
├── README.md
├── a
│   ├── Dockerfile
│   ├── node_modules/
├── docker-compose.yml
├── b
│   ├── Dockerfile
├── c
│   ├── Dockerfile
│   ├── README.md
│   └── vendor/
│   ├── node_modules/
└── d
    ├── Dockerfile

How do I ignore node modules in a and c for the sake of build context?

@thaJeztah
Copy link
Member

In your docker-compose you can specify the "context", so for docker-compose to build a/Dockerfile you just specify build ./a/ then, for building that dockerfile, docker will tar the content of "a" and send it to the daemon. (see https://docs.docker.com/compose/compose-file/#/build)

If your source code doesn't change, repeated builds should be able to use the cache, but docker will always send the build-context (to verify if the source files changed)

In addition, you can use a .dockerignore file to exclude files from being added to your image

@krainboltgreene
Copy link
Author

@thaJeztah I feel like I've tried to use .dockerignore and it wouldn't ignore, but maybe I was just doing it wrong. I'll give it another try.

@krainboltgreene
Copy link
Author

Also, thanks a lot for the information.

@pafmaf
Copy link

pafmaf commented Jul 27, 2017

I feel like I've tried to use .dockerignore and it wouldn't ignore, but maybe I was just doing it wrong. I'll give it another try.

We've had * in our .dockerignore and it wouldn't work for node_modules, adding the node paths specifically reduces build time by 6 mins. Not related to this project tho. lsof hinted us that way.

@thaJeztah
Copy link
Member

Docker 17.07 will add an option to "incrementally" send the build-context, see #32677, #33786, and docker/cli#231, which may be helpful for various use cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants