There is small config of docker-compose with Dockerfiles and .dockerignore files I have in subdirectories. I can't understand why my images after build include everything even I have some items to ignore in .dockerignore. Here is what I have
docker-compose.yml
docker
├── app
│ ├── Dockerfile
│ └── .dockerignore
└── web
├── Dockerfile
├── nginx.conf
└── .dockerignore
Example of .dockerignore:
**/.dockerignore
docker-compose.yml
log
**/log
../../log
I just run this as follows:
docker-compose up -d --build --no-cache
None of the above ignored.. What am I doing wrong?
docker-compose version 1.23.2, build 1110ad01
Adding Dockerfile for the app service (see docker-compose). Docker-compose packs two images with ROR app and nginx. For both dockerfiles I have dockerignore. So my understanding is that I can say what exactly I want in each. But it is not. How can I ignore some of the files in package? Or should I put my Dockerfile and dockerignore in different paths since build works only inside the context.. I am confused.
FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs imagemagick
# Configuring main directory
RUN mkdir -p /var/www/example.com
WORKDIR /var/www/example.com
# Setting env up
ENV RAILS_ENV='production'
ENV RACK_ENV='production'
# Adding gems
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install --jobs 20 --retry 5 --without development test
# Adding project files
COPY . .
EXPOSE 3000
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
So I thought that COPY . .
checks .dockerignore first.. no?
You have 2 Dockerfiles
, which have their separate contexts. In each context (folder) you have .dockerignore
, and that is correct. But .dockerignore
does not work outside of build context, that means using ../../
is wrong.
I guess you are supposing these files to apply to docker
folder, but in fact they apply to docker/app
and docker/web
respectively.
The build process is following:
First docker cli
packs the context (folder with Dockerfile
if not specified explicitly) and sends it to docker daemon
. Nothing outside this folder is sent. It is written explicitly for COPY
command, which is used to put the context items into container:
The
src
path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
If there is .dockerignore
, the ignored files are excluded before packing.
The .dockerignore
needs to be in the root directory/context folder as you specified in the docker-compose.yml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With