compose icon indicating copy to clipboard operation
compose copied to clipboard

docker-compose build ignoring .dockerignore?

Open devinrsmith opened this issue 11 years ago • 112 comments

I've got a full example repo here:

https://github.com/devinrsmith/docker-compose-build-test

If I'm using docker-compose build incorrectly, please let me know!

devinrsmith avatar Jun 26 '15 21:06 devinrsmith

You have problem with file format.

In your .dockerignore change subdir/ to subdir.

neciu avatar Jun 29 '15 09:06 neciu

Why does the .dockerignore work for docker build -t subdir ../ but not docker-compose build?

devinrsmith avatar Jun 29 '15 13:06 devinrsmith

I am having the same issue running docker-compose 1.2.0. Running vanilla docker build pulls in the ignore file and builds the image, np there. However docker-compose does not use the ignore file, with or without the trailing slash.

fChristenson avatar Jun 30 '15 19:06 fChristenson

Looks like a docker-py issue; a fix is being worked on in https://github.com/docker/docker-py/pull/604. Marking this as a bug to remind us to update our docker-py version once the fix is out.

aanand avatar Jul 02 '15 08:07 aanand

@aanand looks like https://github.com/docker/docker-py/pull/604 stalled and was removed from the milestone there?

thaJeztah avatar Aug 16 '15 17:08 thaJeztah

@thaJeztah I've created https://github.com/docker/docker-py/pull/721 to continue the work.

aanand avatar Aug 18 '15 13:08 aanand

Hi,

I'm facing one strange problem with .dockerignore:

*.sh

!awesome/script.sh

with docker build all is fine, but docker-compose didn't see "awesome/script.sh"

Am I in the same issue ?

twillouer avatar Sep 08 '15 23:09 twillouer

@twillouer that's a known bug, fixed by https://github.com/docker/docker-py/pull/721 - it'll be fixed on the Compose side in 1.5.0.

aanand avatar Sep 09 '15 00:09 aanand

thanks !

twillouer avatar Sep 09 '15 13:09 twillouer

This still seems to be broken even on latest git master on some machines. It doesn't work for me on a machine given this configuration:

Debian 8.2 with kernel 3.16.0 with lxc-docker version 1.7.1, build 786b29d docker-compose is git master, HEAD is at dabf1e8657674014a5bc89f99edbf2fe0629bb71

The .dockerignore works fine for docker build (which runs instantly), but not for docker-compose (which uploads stuff it shouldn't upload for various minutes).

Also see #2100

ghost avatar Sep 30 '15 11:09 ghost

I have same problem. docker-compose ignores ".dockerignore". "docker build" works fine. System: windows 10

vladkolotvin avatar Oct 14 '15 12:10 vladkolotvin

I'm experiencing the same problem using the Docker Toolbox that was released yesterday:

  • Windows 7 x64
  • Docker version 1.9.0, build 76d6bc9
  • Docker-Compose 1.5.0

xrstf avatar Nov 05 '15 12:11 xrstf

It sounds like we're still having problems with .dockerignore. If you're experiencing these problems with compose 1.5.0, please include a sample .dockerignore and directory structure so we can reproduce the error.

dnephin avatar Nov 05 '15 16:11 dnephin

Sorry for not provide a smaller usecase, but this is how I noticed the problem:

I have this package.json for my project:

{
  "dependencies": {
    "grunt-contrib-uglify": "^0.9.2"
  }
}

Plus I have this docker-compose.yml:

web:
  build: .

The Dockerfile looks like this:

FROM node:0.12

My .dockerignore contains one line (I tried adding a trailing slash, but the problem persisted):

node_modules

Now I can do

> npm install
  (...snip...)
> docker build .
Sending build context to Docker daemon  5.12 kB

Awesome, it works, only 5 KiB are sent (node_modules is roughly 10 MiB in total). With docker-compose in Q:\sites\test:

> npm install
  (...snip...)
> docker-compose up
Building web
Traceback (most recent call last):
  File "D:\opt\python\Scripts\docker-compose-script.py", line 9, in <module>
    load_entry_point('docker-compose==1.5.0dev', 'console_scripts', 'docker-compose')()
  File "D:\opt\python\lib\site-packages\compose\cli\main.py", line 54, in main
    command.sys_dispatch()
  File "D:\opt\python\lib\site-packages\compose\cli\docopt_command.py", line 23, in sys_dispatch
    self.dispatch(sys.argv[1:], None)
  File "D:\opt\python\lib\site-packages\compose\cli\docopt_command.py", line 26, in dispatch
    self.perform_command(*self.parse(argv, global_options))
  File "D:\opt\python\lib\site-packages\compose\cli\main.py", line 170, in perform_command
    handler(project, command_options)
  File "D:\opt\python\lib\site-packages\compose\cli\main.py", line 583, in up
    detached=detached
  File "D:\opt\python\lib\site-packages\compose\project.py", line 313, in up
    detached=detached
  File "D:\opt\python\lib\site-packages\compose\service.py", line 404, in execute_convergence_plan
    container = self.create_container(do_build=do_build)
  File "D:\opt\python\lib\site-packages\compose\service.py", line 303, in create_container
    self.ensure_image_exists(do_build=do_build)
  File "D:\opt\python\lib\site-packages\compose\service.py", line 326, in ensure_image_exists
    self.build()
  File "D:\opt\python\lib\site-packages\compose\service.py", line 718, in build
    dockerfile=self.options.get('dockerfile', None),
  File "D:\opt\python\lib\site-packages\docker\api\build.py", line 48, in build
    context = utils.tar(path, exclude=exclude, dockerfile=dockerfile)
  File "D:\opt\python\lib\site-packages\docker\utils\utils.py", line 85, in tar
    t.add(os.path.join(root, path), arcname=path, recursive=False)
  File "D:\opt\python\lib\tarfile.py", line 1998, in add
    tarinfo = self.gettarinfo(name, arcname)
  File "D:\opt\python\lib\tarfile.py", line 1870, in gettarinfo
    statres = os.lstat(name)
WindowsError: [Error 3] Das System kann den angegebenen Pfad nicht finden: 'Q:\\sites\\test\\node_modules\\grunt-contrib-uglify\\node_modules\\maxmin\\node_modules\\pretty-bytes\\node_modules\\meow\\node_modules\\normalize-package-data\\node_modules\\validate-npm-package-license\\node_modules\\spdx-correct\\node_modules\\spdx-license-ids\\spdx-license-ids.json'

(I am using 1.5.0dev on this machine, but I got the exact same problem on my other machine with 1.5.0 final).

With node, I often encounter problems with too long paths and stuff on Windows, but the fact that Docker-Compose is attempting to tar up the node_modules is the indicator that the .dockerignore is ignored.

xrstf avatar Nov 05 '15 16:11 xrstf

FWIW, I am still having issues with this on Linux (Ubuntu) with docker-compose 1.5.0dev, so it's probably not isolated to Windows. However, it's on a production machine so I cannot easily put together a minimal test case (it works fine on my testing machine).

ghost avatar Nov 07 '15 20:11 ghost

I am also having this issue.

Directory structure:

docker-compose.yml
web
  + .dockerignore
  + Dockerfile
  + node_modules
    + ...

docker-compose.yaml

web:
  build: web
  tty: true
  ports:
    - 8081:5000

Dockerfile

FROM microsoft/aspnet

# Curl, node, npm, bower, grunt
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs
RUN npm install -g bower
RUN npm install -g grunt-bower-cli
RUN npm install -g grunt
RUN npm install -g grunt-cli
RUN npm install -g grunt-bower-task

# Copy the project.json file first, then do a restore.
# This ensures that as long as project.json doesn't change, it will avoid
# doing a package restore
COPY project.json /app/
COPY bower.json /app/
COPY gruntfile.js /app/
COPY package.json /app/
WORKDIR /app

RUN ["dnu", "restore"]

# Then copy the rest of the files
COPY . /app

# Expose the port that the website listens on
EXPOSE 5000
# And start the website
ENTRYPOINT ["dnx", "-p", "project.json", "web"]

.dockerignore

node_modules

Result:

Pi@Ricci MINGW64 /d/proj/Repro
$ docker-compose build
Building web
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\projects\compose\compose\cli\main.py", line 54, in main
  File "C:\projects\compose\compose\cli\docopt_command.py", line 23, in sys_dispatch
  File "C:\projects\compose\compose\cli\docopt_command.py", line 26, in dispatch
  File "C:\projects\compose\compose\cli\main.py", line 171, in perform_command
  File "C:\projects\compose\compose\cli\main.py", line 192, in build
  File "C:\projects\compose\compose\project.py", line 235, in build
  File "C:\projects\compose\compose\service.py", line 683, in build
  File "c:\projects\compose\venv\lib\site-packages\docker\api\build.py", line 48, in build
  File "c:\projects\compose\venv\lib\site-packages\docker\utils\utils.py", line 85, in tar
  File "c:\python27-x64\Lib\tarfile.py", line 2000, in add
  File "c:\python27-x64\Lib\tarfile.py", line 1872, in gettarinfo
WindowsError: [Error 3] The system cannot find the path specified: 'D:\\proj\\Repro\\web\\node_modules\\babel-preset-react\\node_modules\\babel-plugin-transform-react-jsx\\node_modules\\babel-helper-builder-react-jsx\\node_modules\\babel-types\\node_modules\\babel-traverse\\node_modules\\babel-code-frame\\node_modules\\js-tokens\\changelog.md'
docker-compose returned -1

Quantumplation avatar Dec 22 '15 23:12 Quantumplation

+1

keatz55 avatar Dec 30 '15 23:12 keatz55

Did anybody find a workaround? I am trying to do everything in only the Dockerfile, but haven't had any luck yet.

keatz55 avatar Dec 30 '15 23:12 keatz55

I'm getting this issue as well, could it be related to the node version everyone is running? Via this issue: https://github.com/npm/npm/issues/3697 .. I imagine upgrading node (more specifically to npm 3+) would fix it, but that's more of a nuclear option, and .dockerignore should still work.

esc-rtn avatar Jan 06 '16 14:01 esc-rtn

Again despite this being apparently ignored, I am seeing this on a Linux machine as well.

ghost avatar Jan 06 '16 18:01 ghost