Shared files between containers with docker
I have a project structure like the following
app/
docker-compose.yml
module1/
Dockerfile
module1.py
module2/
Dockerfile
module2.py
common/
common_things.py
In my Dockerfile for module1 I have
COPY module1.py /app
COPY ../common /app/common
But Docker does not like this second line. Error is below
ERROR: Service 'module1' failed to build: COPY failed: Forbidden path outside the build context: ../common ()
How do I tell Docker, through Dockerfile or Docker-compose, that it is okay for module1 to grab files from ../common
? I could symlink common so that module1 and module2 have common in their respective dirs but that feels like overkill...
Extra credit: What is best practice for sharing files across Docker containers? Perhaps there is another way that I am unaware of.
docker docker-compose
add a comment |
I have a project structure like the following
app/
docker-compose.yml
module1/
Dockerfile
module1.py
module2/
Dockerfile
module2.py
common/
common_things.py
In my Dockerfile for module1 I have
COPY module1.py /app
COPY ../common /app/common
But Docker does not like this second line. Error is below
ERROR: Service 'module1' failed to build: COPY failed: Forbidden path outside the build context: ../common ()
How do I tell Docker, through Dockerfile or Docker-compose, that it is okay for module1 to grab files from ../common
? I could symlink common so that module1 and module2 have common in their respective dirs but that feels like overkill...
Extra credit: What is best practice for sharing files across Docker containers? Perhaps there is another way that I am unaware of.
docker docker-compose
Check this question: stackoverflow.com/questions/27068596/… Also this issue: github.com/moby/moby/issues/2745
– Emruz Hossain
Nov 22 '18 at 4:04
If you need share files between containers, try using-v
orvolumes
options to map host files/dir to your container. with volumes mapping, you don't need to rebuild your image whenever file changed. docs.docker.com/compose/compose-file/…
– Enix
Nov 22 '18 at 9:03
Possible duplicate of Making a dependencies container and mount its volumes on other containers
– Siyu
Nov 22 '18 at 12:28
This question is not about volumes as OP searches for a build-time solution.
– fab
Nov 22 '18 at 13:24
add a comment |
I have a project structure like the following
app/
docker-compose.yml
module1/
Dockerfile
module1.py
module2/
Dockerfile
module2.py
common/
common_things.py
In my Dockerfile for module1 I have
COPY module1.py /app
COPY ../common /app/common
But Docker does not like this second line. Error is below
ERROR: Service 'module1' failed to build: COPY failed: Forbidden path outside the build context: ../common ()
How do I tell Docker, through Dockerfile or Docker-compose, that it is okay for module1 to grab files from ../common
? I could symlink common so that module1 and module2 have common in their respective dirs but that feels like overkill...
Extra credit: What is best practice for sharing files across Docker containers? Perhaps there is another way that I am unaware of.
docker docker-compose
I have a project structure like the following
app/
docker-compose.yml
module1/
Dockerfile
module1.py
module2/
Dockerfile
module2.py
common/
common_things.py
In my Dockerfile for module1 I have
COPY module1.py /app
COPY ../common /app/common
But Docker does not like this second line. Error is below
ERROR: Service 'module1' failed to build: COPY failed: Forbidden path outside the build context: ../common ()
How do I tell Docker, through Dockerfile or Docker-compose, that it is okay for module1 to grab files from ../common
? I could symlink common so that module1 and module2 have common in their respective dirs but that feels like overkill...
Extra credit: What is best practice for sharing files across Docker containers? Perhaps there is another way that I am unaware of.
docker docker-compose
docker docker-compose
asked Nov 22 '18 at 1:54
cjavier70cjavier70
981112
981112
Check this question: stackoverflow.com/questions/27068596/… Also this issue: github.com/moby/moby/issues/2745
– Emruz Hossain
Nov 22 '18 at 4:04
If you need share files between containers, try using-v
orvolumes
options to map host files/dir to your container. with volumes mapping, you don't need to rebuild your image whenever file changed. docs.docker.com/compose/compose-file/…
– Enix
Nov 22 '18 at 9:03
Possible duplicate of Making a dependencies container and mount its volumes on other containers
– Siyu
Nov 22 '18 at 12:28
This question is not about volumes as OP searches for a build-time solution.
– fab
Nov 22 '18 at 13:24
add a comment |
Check this question: stackoverflow.com/questions/27068596/… Also this issue: github.com/moby/moby/issues/2745
– Emruz Hossain
Nov 22 '18 at 4:04
If you need share files between containers, try using-v
orvolumes
options to map host files/dir to your container. with volumes mapping, you don't need to rebuild your image whenever file changed. docs.docker.com/compose/compose-file/…
– Enix
Nov 22 '18 at 9:03
Possible duplicate of Making a dependencies container and mount its volumes on other containers
– Siyu
Nov 22 '18 at 12:28
This question is not about volumes as OP searches for a build-time solution.
– fab
Nov 22 '18 at 13:24
Check this question: stackoverflow.com/questions/27068596/… Also this issue: github.com/moby/moby/issues/2745
– Emruz Hossain
Nov 22 '18 at 4:04
Check this question: stackoverflow.com/questions/27068596/… Also this issue: github.com/moby/moby/issues/2745
– Emruz Hossain
Nov 22 '18 at 4:04
If you need share files between containers, try using
-v
or volumes
options to map host files/dir to your container. with volumes mapping, you don't need to rebuild your image whenever file changed. docs.docker.com/compose/compose-file/…– Enix
Nov 22 '18 at 9:03
If you need share files between containers, try using
-v
or volumes
options to map host files/dir to your container. with volumes mapping, you don't need to rebuild your image whenever file changed. docs.docker.com/compose/compose-file/…– Enix
Nov 22 '18 at 9:03
Possible duplicate of Making a dependencies container and mount its volumes on other containers
– Siyu
Nov 22 '18 at 12:28
Possible duplicate of Making a dependencies container and mount its volumes on other containers
– Siyu
Nov 22 '18 at 12:28
This question is not about volumes as OP searches for a build-time solution.
– fab
Nov 22 '18 at 13:24
This question is not about volumes as OP searches for a build-time solution.
– fab
Nov 22 '18 at 13:24
add a comment |
1 Answer
1
active
oldest
votes
You can achieve it by passing the entire app directory as build-context.
The docker-compose.yml
would look like this:
version: '3'
services:
module1:
build:
context: ./
dockerfile: module1/Dockerfile
...
The (first) Dockerfile
would look like this:
...
COPY module1/module1.py /app
COPY common /app/common
...
Some further comments:
Normally you would publish common parts of your two docker images as a shared library. I'm not very familiar with python but I believe it would boil down to:
- publish your
common_things.py
as a python package on some python repository, so that it can be installed throughpip install
- add a
requirements.txt
file in each of your Docker-images and refer to your python package inside it - run
pip install -r requirements.txt
during your Docker-build to install yourcommon_things-package
in the docker-image.
However, this might be overkill for your usecase, so I think your solution for sharing the file might be the good choice for you.
Changing context was exactly what I needed. Thank you
– cjavier70
Nov 24 '18 at 20:46
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%2f53422846%2fshared-files-between-containers-with-docker%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 can achieve it by passing the entire app directory as build-context.
The docker-compose.yml
would look like this:
version: '3'
services:
module1:
build:
context: ./
dockerfile: module1/Dockerfile
...
The (first) Dockerfile
would look like this:
...
COPY module1/module1.py /app
COPY common /app/common
...
Some further comments:
Normally you would publish common parts of your two docker images as a shared library. I'm not very familiar with python but I believe it would boil down to:
- publish your
common_things.py
as a python package on some python repository, so that it can be installed throughpip install
- add a
requirements.txt
file in each of your Docker-images and refer to your python package inside it - run
pip install -r requirements.txt
during your Docker-build to install yourcommon_things-package
in the docker-image.
However, this might be overkill for your usecase, so I think your solution for sharing the file might be the good choice for you.
Changing context was exactly what I needed. Thank you
– cjavier70
Nov 24 '18 at 20:46
add a comment |
You can achieve it by passing the entire app directory as build-context.
The docker-compose.yml
would look like this:
version: '3'
services:
module1:
build:
context: ./
dockerfile: module1/Dockerfile
...
The (first) Dockerfile
would look like this:
...
COPY module1/module1.py /app
COPY common /app/common
...
Some further comments:
Normally you would publish common parts of your two docker images as a shared library. I'm not very familiar with python but I believe it would boil down to:
- publish your
common_things.py
as a python package on some python repository, so that it can be installed throughpip install
- add a
requirements.txt
file in each of your Docker-images and refer to your python package inside it - run
pip install -r requirements.txt
during your Docker-build to install yourcommon_things-package
in the docker-image.
However, this might be overkill for your usecase, so I think your solution for sharing the file might be the good choice for you.
Changing context was exactly what I needed. Thank you
– cjavier70
Nov 24 '18 at 20:46
add a comment |
You can achieve it by passing the entire app directory as build-context.
The docker-compose.yml
would look like this:
version: '3'
services:
module1:
build:
context: ./
dockerfile: module1/Dockerfile
...
The (first) Dockerfile
would look like this:
...
COPY module1/module1.py /app
COPY common /app/common
...
Some further comments:
Normally you would publish common parts of your two docker images as a shared library. I'm not very familiar with python but I believe it would boil down to:
- publish your
common_things.py
as a python package on some python repository, so that it can be installed throughpip install
- add a
requirements.txt
file in each of your Docker-images and refer to your python package inside it - run
pip install -r requirements.txt
during your Docker-build to install yourcommon_things-package
in the docker-image.
However, this might be overkill for your usecase, so I think your solution for sharing the file might be the good choice for you.
You can achieve it by passing the entire app directory as build-context.
The docker-compose.yml
would look like this:
version: '3'
services:
module1:
build:
context: ./
dockerfile: module1/Dockerfile
...
The (first) Dockerfile
would look like this:
...
COPY module1/module1.py /app
COPY common /app/common
...
Some further comments:
Normally you would publish common parts of your two docker images as a shared library. I'm not very familiar with python but I believe it would boil down to:
- publish your
common_things.py
as a python package on some python repository, so that it can be installed throughpip install
- add a
requirements.txt
file in each of your Docker-images and refer to your python package inside it - run
pip install -r requirements.txt
during your Docker-build to install yourcommon_things-package
in the docker-image.
However, this might be overkill for your usecase, so I think your solution for sharing the file might be the good choice for you.
edited Nov 22 '18 at 13:19
answered Nov 22 '18 at 13:03
fabfab
90811224
90811224
Changing context was exactly what I needed. Thank you
– cjavier70
Nov 24 '18 at 20:46
add a comment |
Changing context was exactly what I needed. Thank you
– cjavier70
Nov 24 '18 at 20:46
Changing context was exactly what I needed. Thank you
– cjavier70
Nov 24 '18 at 20:46
Changing context was exactly what I needed. Thank you
– cjavier70
Nov 24 '18 at 20:46
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.
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%2f53422846%2fshared-files-between-containers-with-docker%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
Check this question: stackoverflow.com/questions/27068596/… Also this issue: github.com/moby/moby/issues/2745
– Emruz Hossain
Nov 22 '18 at 4:04
If you need share files between containers, try using
-v
orvolumes
options to map host files/dir to your container. with volumes mapping, you don't need to rebuild your image whenever file changed. docs.docker.com/compose/compose-file/…– Enix
Nov 22 '18 at 9:03
Possible duplicate of Making a dependencies container and mount its volumes on other containers
– Siyu
Nov 22 '18 at 12:28
This question is not about volumes as OP searches for a build-time solution.
– fab
Nov 22 '18 at 13:24