Docker-compose and .dockerignore

Multi tool use
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?
docker docker-compose
add a comment |
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?
docker docker-compose
Try*
instead of**
. I think**
doesn't work in.dockerignore
. Also, what exactly do your images include that you want to be excluded?
– amorfis
Dec 27 at 13:37
1
The actual contents of thedocker-compose.yml
file seems essential to debug this; seeing the twoDockerfile
s wouldn't hurt either. If you're using Docker bind mounts (volumes:
) to replace everything in the image with your local source tree, that doesn't look at the.dockerignore
files.
– David Maze
Dec 27 at 14:14
The build should ignore these files, so you'll need to provide a Minimal, Complete, and Verifiable example to get help on this. Your examples are incomplete and haven't been reduced to the minimum needed to allow someone else to try to reproduce the issue.
– BMitch
Dec 27 at 19:39
add a comment |
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?
docker docker-compose
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?
docker docker-compose
docker docker-compose
edited Dec 27 at 16:42
asked Dec 27 at 13:31
Evgeny
443417
443417
Try*
instead of**
. I think**
doesn't work in.dockerignore
. Also, what exactly do your images include that you want to be excluded?
– amorfis
Dec 27 at 13:37
1
The actual contents of thedocker-compose.yml
file seems essential to debug this; seeing the twoDockerfile
s wouldn't hurt either. If you're using Docker bind mounts (volumes:
) to replace everything in the image with your local source tree, that doesn't look at the.dockerignore
files.
– David Maze
Dec 27 at 14:14
The build should ignore these files, so you'll need to provide a Minimal, Complete, and Verifiable example to get help on this. Your examples are incomplete and haven't been reduced to the minimum needed to allow someone else to try to reproduce the issue.
– BMitch
Dec 27 at 19:39
add a comment |
Try*
instead of**
. I think**
doesn't work in.dockerignore
. Also, what exactly do your images include that you want to be excluded?
– amorfis
Dec 27 at 13:37
1
The actual contents of thedocker-compose.yml
file seems essential to debug this; seeing the twoDockerfile
s wouldn't hurt either. If you're using Docker bind mounts (volumes:
) to replace everything in the image with your local source tree, that doesn't look at the.dockerignore
files.
– David Maze
Dec 27 at 14:14
The build should ignore these files, so you'll need to provide a Minimal, Complete, and Verifiable example to get help on this. Your examples are incomplete and haven't been reduced to the minimum needed to allow someone else to try to reproduce the issue.
– BMitch
Dec 27 at 19:39
Try
*
instead of **
. I think **
doesn't work in .dockerignore
. Also, what exactly do your images include that you want to be excluded?– amorfis
Dec 27 at 13:37
Try
*
instead of **
. I think **
doesn't work in .dockerignore
. Also, what exactly do your images include that you want to be excluded?– amorfis
Dec 27 at 13:37
1
1
The actual contents of the
docker-compose.yml
file seems essential to debug this; seeing the two Dockerfile
s wouldn't hurt either. If you're using Docker bind mounts (volumes:
) to replace everything in the image with your local source tree, that doesn't look at the .dockerignore
files.– David Maze
Dec 27 at 14:14
The actual contents of the
docker-compose.yml
file seems essential to debug this; seeing the two Dockerfile
s wouldn't hurt either. If you're using Docker bind mounts (volumes:
) to replace everything in the image with your local source tree, that doesn't look at the .dockerignore
files.– David Maze
Dec 27 at 14:14
The build should ignore these files, so you'll need to provide a Minimal, Complete, and Verifiable example to get help on this. Your examples are incomplete and haven't been reduced to the minimum needed to allow someone else to try to reproduce the issue.
– BMitch
Dec 27 at 19:39
The build should ignore these files, so you'll need to provide a Minimal, Complete, and Verifiable example to get help on this. Your examples are incomplete and haven't been reduced to the minimum needed to allow someone else to try to reproduce the issue.
– BMitch
Dec 27 at 19:39
add a comment |
1 Answer
1
active
oldest
votes
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.
Thanks for heads up. Can you check dockerfile above. Still not clear.
– Evgeny
Dec 27 at 16:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945934%2fdocker-compose-and-dockerignore%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Thanks for heads up. Can you check dockerfile above. Still not clear.
– Evgeny
Dec 27 at 16:43
add a comment |
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.
Thanks for heads up. Can you check dockerfile above. Still not clear.
– Evgeny
Dec 27 at 16:43
add a comment |
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.
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.
edited Dec 27 at 13:49
answered Dec 27 at 13:39
grapes
2,522115
2,522115
Thanks for heads up. Can you check dockerfile above. Still not clear.
– Evgeny
Dec 27 at 16:43
add a comment |
Thanks for heads up. Can you check dockerfile above. Still not clear.
– Evgeny
Dec 27 at 16:43
Thanks for heads up. Can you check dockerfile above. Still not clear.
– Evgeny
Dec 27 at 16:43
Thanks for heads up. Can you check dockerfile above. Still not clear.
– Evgeny
Dec 27 at 16:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945934%2fdocker-compose-and-dockerignore%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
S,RG O 2EtR9CWYC569HeXdM2CXkz0YCk1IZSoGvEW0ZK uPtMhpPbZg1wfDEfRI2EJbxfNnqbP0
Try
*
instead of**
. I think**
doesn't work in.dockerignore
. Also, what exactly do your images include that you want to be excluded?– amorfis
Dec 27 at 13:37
1
The actual contents of the
docker-compose.yml
file seems essential to debug this; seeing the twoDockerfile
s wouldn't hurt either. If you're using Docker bind mounts (volumes:
) to replace everything in the image with your local source tree, that doesn't look at the.dockerignore
files.– David Maze
Dec 27 at 14:14
The build should ignore these files, so you'll need to provide a Minimal, Complete, and Verifiable example to get help on this. Your examples are incomplete and haven't been reduced to the minimum needed to allow someone else to try to reproduce the issue.
– BMitch
Dec 27 at 19:39