Closed Fuco1 closed 5 years ago
Sorry I don't understand your question. Can you maybe post your directory structure and the content of your .dockerignore
file?
in general: I don't know how @dnephin wants this handled but this seems like a question around usage for which the gitter chat seems to be the better place.
If I understand correctly the request is about specifcying different .dockerignore
files for different image build tasks.
Right now I use a lot of the docker/cli
and docker/docker/client
code as libraries. I have been hoping that this feature would be supported upstream, but unfortunately it doesn't look like it will be: https://github.com/moby/moby/issues/12886
It's definitely possible that dobi
could add support for this by forking the dependency and adding support. If someone is interested in contributing such a feature I should be able to help them out.
@Enteee Dockerfiles have to be in the "root" of the application because you can not COPY ../...
to the parent directory.
Using dobi I build some images to run jobs that only prepare some data for the final result and having 20 dockerfiles in the root is annoying. So I store them in ./build
directory. But then this gets copied into the final image once I do COPY . /app
if ./build
directory is not in .dockerignore
.
If I however put it in the ignore file then using a dobi build job with context: .
and dockerfile: build/Dockerfile.foo
does not work because that directory does not exist to docker and so no files from in there can be copied to the image (I use root context because I need access to the app).
I can copy the directory structure when I get to the office if necessary.
I also generally keep my dockerfiles in a sub-directory, usually dockerfiles/
or dobifiles/
.
I never really do a COPY . /app
, but it should still work to ignore that directory.
It is possible to use a Dockerfile from outside of the build context (or a dockerfile that is ignored in .dockerignore`). See this example: https://github.com/dnephin/dobi/commit/940cfe1a79d8d2557a33a487280ba98794cf59e7
It should fail on the line that tries to cat
the Dockerfile, because the file isn't there. It seems it still adds the directory that is ignored, I'm not sure why that is.
The concrete example is this Dockerfile.env
inside ./build
.
FROM alpine
RUN apk -U add bash
COPY build/env.sh /usr/bin/env.sh
COPY yarn.lock /code/yarn.lock
WORKDIR /code
CMD ["/usr/bin/env.sh"]
The dobi job was like this
image=setup-env:
image: setup-env
context: .
dockerfile: ./build/Dockerfile.env
Now the COPY build/env.sh /usr/bin/env.sh
instruction won't work because that file is ignored (.dockerignore
contains ./build
directory).
I've solved this by moving the context to ./build
and then mounting the yarn file as a volume instead. So my particular issue was worked around, maybe I was just trying to do something silly.
I think we can close this issue. Once this is supported upstream and there's a need for it we can add the feature to dobi, but it seems like it's not that necessary (as I've found a work around and nobody else asked for it).
I would like to have some auxiliary images built from a
./build
directory context but this is currently in my.dockerignore
so that those files don't end up in the final images.Is there any way to ignore the ignore file for the helper images?