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










share|improve this question



















  • 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






  • 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















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










share|improve this question



















  • 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






  • 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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 13:03

























asked Nov 7 at 21:00









Derilius

213




213







  • 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






  • 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




    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




    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













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





share|improve this answer




















    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',
    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
    );



    );













    draft saved

    draft discarded


















    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

























    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





    share|improve this answer
























      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





      share|improve this answer






















        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





        share|improve this answer












        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 21:34









        Derilius

        213




        213



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto