Shared volume between Docker containers with python code
up vote
1
down vote
favorite
Maybe i'm going at it wrong, but i can't seem to get a shared volume working between two docker containers running custom python code.
I'm using the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/temp
volumes:
pdffolder:
The idea is that the producer service polls an exchange server for information and a pdf-file. The consumer service then has to send this information and pdf-file elsewhere. During this action I have to store the pdf locally temporally.
I access the volumes from the custom python-code like this:
producer
# attachment = object I get when requesting attachments from an exchange server
# path to pdf to be saved
pdf_path = os.path.join("temp", attachment.name)
with open(pdf_path, 'wb') as f:
f.write(attachment.content)
# now in this container, /temp/attachment.pdf exists. I then send this path in a message to the consumer (along with other information)
consumer
# consumer tries to find path created by producer (/temp/attachment.pdf) via
pdf_path = os.path.join("temp", "attachment.pdf")
Via the command line i can see that the producer-container is writing the files to temp/attachment.pdf like expected. The consumer-container however sees no files (resulting in errors).
Btw, I am running the containers on docker for windows
python docker volume
add a comment |
up vote
1
down vote
favorite
Maybe i'm going at it wrong, but i can't seem to get a shared volume working between two docker containers running custom python code.
I'm using the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/temp
volumes:
pdffolder:
The idea is that the producer service polls an exchange server for information and a pdf-file. The consumer service then has to send this information and pdf-file elsewhere. During this action I have to store the pdf locally temporally.
I access the volumes from the custom python-code like this:
producer
# attachment = object I get when requesting attachments from an exchange server
# path to pdf to be saved
pdf_path = os.path.join("temp", attachment.name)
with open(pdf_path, 'wb') as f:
f.write(attachment.content)
# now in this container, /temp/attachment.pdf exists. I then send this path in a message to the consumer (along with other information)
consumer
# consumer tries to find path created by producer (/temp/attachment.pdf) via
pdf_path = os.path.join("temp", "attachment.pdf")
Via the command line i can see that the producer-container is writing the files to temp/attachment.pdf like expected. The consumer-container however sees no files (resulting in errors).
Btw, I am running the containers on docker for windows
python docker volume
2
Thepfdfolder
in your service definition doesn't matchpdffolder
in the top-level volumes block; it looks like that should produce a startup error. The paths you provide also look suspicious (forward vs. back slash, relative vs. absolute path). Can you provide a Minimal, Complete, and Verifiable example that demonstrates the issue?
– David Maze
Nov 8 at 0:42
1
I changed the original question. There were indeed some problems in the spelling of 'pdffolder'. I fixed that. I also changed the way that the paths are defined in the python code. I'm used to developing on windows and realised that defining paths on linux is done differently. Just to be sure, I used os.path.join. I'm still facing the problem that the consumer container can't find the file that was saved to the shared volume.
– Derilius
Nov 11 at 12:49
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Maybe i'm going at it wrong, but i can't seem to get a shared volume working between two docker containers running custom python code.
I'm using the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/temp
volumes:
pdffolder:
The idea is that the producer service polls an exchange server for information and a pdf-file. The consumer service then has to send this information and pdf-file elsewhere. During this action I have to store the pdf locally temporally.
I access the volumes from the custom python-code like this:
producer
# attachment = object I get when requesting attachments from an exchange server
# path to pdf to be saved
pdf_path = os.path.join("temp", attachment.name)
with open(pdf_path, 'wb') as f:
f.write(attachment.content)
# now in this container, /temp/attachment.pdf exists. I then send this path in a message to the consumer (along with other information)
consumer
# consumer tries to find path created by producer (/temp/attachment.pdf) via
pdf_path = os.path.join("temp", "attachment.pdf")
Via the command line i can see that the producer-container is writing the files to temp/attachment.pdf like expected. The consumer-container however sees no files (resulting in errors).
Btw, I am running the containers on docker for windows
python docker volume
Maybe i'm going at it wrong, but i can't seem to get a shared volume working between two docker containers running custom python code.
I'm using the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/temp
volumes:
pdffolder:
The idea is that the producer service polls an exchange server for information and a pdf-file. The consumer service then has to send this information and pdf-file elsewhere. During this action I have to store the pdf locally temporally.
I access the volumes from the custom python-code like this:
producer
# attachment = object I get when requesting attachments from an exchange server
# path to pdf to be saved
pdf_path = os.path.join("temp", attachment.name)
with open(pdf_path, 'wb') as f:
f.write(attachment.content)
# now in this container, /temp/attachment.pdf exists. I then send this path in a message to the consumer (along with other information)
consumer
# consumer tries to find path created by producer (/temp/attachment.pdf) via
pdf_path = os.path.join("temp", "attachment.pdf")
Via the command line i can see that the producer-container is writing the files to temp/attachment.pdf like expected. The consumer-container however sees no files (resulting in errors).
Btw, I am running the containers on docker for windows
python docker volume
python docker volume
edited Nov 11 at 13:03
asked Nov 7 at 21:00
Derilius
213
213
2
Thepfdfolder
in your service definition doesn't matchpdffolder
in the top-level volumes block; it looks like that should produce a startup error. The paths you provide also look suspicious (forward vs. back slash, relative vs. absolute path). Can you provide a Minimal, Complete, and Verifiable example that demonstrates the issue?
– David Maze
Nov 8 at 0:42
1
I changed the original question. There were indeed some problems in the spelling of 'pdffolder'. I fixed that. I also changed the way that the paths are defined in the python code. I'm used to developing on windows and realised that defining paths on linux is done differently. Just to be sure, I used os.path.join. I'm still facing the problem that the consumer container can't find the file that was saved to the shared volume.
– Derilius
Nov 11 at 12:49
add a comment |
2
Thepfdfolder
in your service definition doesn't matchpdffolder
in the top-level volumes block; it looks like that should produce a startup error. The paths you provide also look suspicious (forward vs. back slash, relative vs. absolute path). Can you provide a Minimal, Complete, and Verifiable example that demonstrates the issue?
– David Maze
Nov 8 at 0:42
1
I changed the original question. There were indeed some problems in the spelling of 'pdffolder'. I fixed that. I also changed the way that the paths are defined in the python code. I'm used to developing on windows and realised that defining paths on linux is done differently. Just to be sure, I used os.path.join. I'm still facing the problem that the consumer container can't find the file that was saved to the shared volume.
– Derilius
Nov 11 at 12:49
2
2
The
pfdfolder
in your service definition doesn't match pdffolder
in the top-level volumes block; it looks like that should produce a startup error. The paths you provide also look suspicious (forward vs. back slash, relative vs. absolute path). Can you provide a Minimal, Complete, and Verifiable example that demonstrates the issue?– David Maze
Nov 8 at 0:42
The
pfdfolder
in your service definition doesn't match pdffolder
in the top-level volumes block; it looks like that should produce a startup error. The paths you provide also look suspicious (forward vs. back slash, relative vs. absolute path). Can you provide a Minimal, Complete, and Verifiable example that demonstrates the issue?– David Maze
Nov 8 at 0:42
1
1
I changed the original question. There were indeed some problems in the spelling of 'pdffolder'. I fixed that. I also changed the way that the paths are defined in the python code. I'm used to developing on windows and realised that defining paths on linux is done differently. Just to be sure, I used os.path.join. I'm still facing the problem that the consumer container can't find the file that was saved to the shared volume.
– Derilius
Nov 11 at 12:49
I changed the original question. There were indeed some problems in the spelling of 'pdffolder'. I fixed that. I also changed the way that the paths are defined in the python code. I'm used to developing on windows and realised that defining paths on linux is done differently. Just to be sure, I used os.path.join. I'm still facing the problem that the consumer container can't find the file that was saved to the shared volume.
– Derilius
Nov 11 at 12:49
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I think I figured out what was wrong. I used the following in both the Dockerfiles for the producer and consumer:
FROM python:3.7-slim
WORKDIR /main
ADD . /main
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD ["python", "-u", "main.py"]
Because I moved the python code to the /main folder in both containers, the temp folder created later (via docker-compose) was to be found at /main/temp, and not just /temp. A little bit weird because the main.py should be at the same level as /temp, but hey it works. I got it working with the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/main/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/main/temp
volumes:
pdffolder:
So i guess the steps to debugging this are:
- Check the spelling of all mentions of volumes in the docker-compose.yml file
- Check the way paths are being built/referenced in the python code (Linux uses a different format to windows)
- Check if the paths that have to be accessed from the python code actually exist
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I think I figured out what was wrong. I used the following in both the Dockerfiles for the producer and consumer:
FROM python:3.7-slim
WORKDIR /main
ADD . /main
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD ["python", "-u", "main.py"]
Because I moved the python code to the /main folder in both containers, the temp folder created later (via docker-compose) was to be found at /main/temp, and not just /temp. A little bit weird because the main.py should be at the same level as /temp, but hey it works. I got it working with the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/main/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/main/temp
volumes:
pdffolder:
So i guess the steps to debugging this are:
- Check the spelling of all mentions of volumes in the docker-compose.yml file
- Check the way paths are being built/referenced in the python code (Linux uses a different format to windows)
- Check if the paths that have to be accessed from the python code actually exist
add a comment |
up vote
0
down vote
accepted
I think I figured out what was wrong. I used the following in both the Dockerfiles for the producer and consumer:
FROM python:3.7-slim
WORKDIR /main
ADD . /main
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD ["python", "-u", "main.py"]
Because I moved the python code to the /main folder in both containers, the temp folder created later (via docker-compose) was to be found at /main/temp, and not just /temp. A little bit weird because the main.py should be at the same level as /temp, but hey it works. I got it working with the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/main/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/main/temp
volumes:
pdffolder:
So i guess the steps to debugging this are:
- Check the spelling of all mentions of volumes in the docker-compose.yml file
- Check the way paths are being built/referenced in the python code (Linux uses a different format to windows)
- Check if the paths that have to be accessed from the python code actually exist
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I think I figured out what was wrong. I used the following in both the Dockerfiles for the producer and consumer:
FROM python:3.7-slim
WORKDIR /main
ADD . /main
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD ["python", "-u", "main.py"]
Because I moved the python code to the /main folder in both containers, the temp folder created later (via docker-compose) was to be found at /main/temp, and not just /temp. A little bit weird because the main.py should be at the same level as /temp, but hey it works. I got it working with the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/main/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/main/temp
volumes:
pdffolder:
So i guess the steps to debugging this are:
- Check the spelling of all mentions of volumes in the docker-compose.yml file
- Check the way paths are being built/referenced in the python code (Linux uses a different format to windows)
- Check if the paths that have to be accessed from the python code actually exist
I think I figured out what was wrong. I used the following in both the Dockerfiles for the producer and consumer:
FROM python:3.7-slim
WORKDIR /main
ADD . /main
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD ["python", "-u", "main.py"]
Because I moved the python code to the /main folder in both containers, the temp folder created later (via docker-compose) was to be found at /main/temp, and not just /temp. A little bit weird because the main.py should be at the same level as /temp, but hey it works. I got it working with the following docker-compose.yml:
version: "2"
services:
rabbitmq:
image: username/rabbitmq
ports:
- 15672:15672
- 5672:5672
producer:
image: username/producer
depends_on:
- rabbitmq
volumes:
- pdffolder:/main/temp
consumer:
image: username/consumer
depends_on:
- producer
volumes:
- pdffolder:/main/temp
volumes:
pdffolder:
So i guess the steps to debugging this are:
- Check the spelling of all mentions of volumes in the docker-compose.yml file
- Check the way paths are being built/referenced in the python code (Linux uses a different format to windows)
- Check if the paths that have to be accessed from the python code actually exist
answered Nov 11 at 21:34
Derilius
213
213
add a comment |
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%2f53197738%2fshared-volume-between-docker-containers-with-python-code%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
2
The
pfdfolder
in your service definition doesn't matchpdffolder
in the top-level volumes block; it looks like that should produce a startup error. The paths you provide also look suspicious (forward vs. back slash, relative vs. absolute path). Can you provide a Minimal, Complete, and Verifiable example that demonstrates the issue?– David Maze
Nov 8 at 0:42
1
I changed the original question. There were indeed some problems in the spelling of 'pdffolder'. I fixed that. I also changed the way that the paths are defined in the python code. I'm used to developing on windows and realised that defining paths on linux is done differently. Just to be sure, I used os.path.join. I'm still facing the problem that the consumer container can't find the file that was saved to the shared volume.
– Derilius
Nov 11 at 12:49