Docker container cannot copy file into volumeHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCopying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repositoryFrom inside of a Docker container, how do I connect to the localhost of the machine?What is the difference between the `COPY` and `ADD` commands in a Dockerfile?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

How to Prove P(a) → ∀x(P(x) ∨ ¬(x = a)) using Natural Deduction

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Was the old ablative pronoun "med" or "mēd"?

What is an equivalently powerful replacement spell for the Yuan-Ti's Suggestion spell?

Why didn't Boeing produce its own regional jet?

Partial fraction expansion confusion

How to enclose theorems and definition in rectangles?

How can a day be of 24 hours?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

Why do I get negative height?

How to find if SQL server backup is encrypted with TDE without restoring the backup

Was the Stack Exchange "Happy April Fools" page fitting with the '90's code?

How to coordinate airplane tickets?

Is it a bad idea to plug the other end of ESD strap to wall ground?

Bullying boss launched a smear campaign and made me unemployable

How do I exit BASH while loop using modulus operator?

How to prevent "they're falling in love" trope

What is a Samsaran Word™?

how do we prove that a sum of two periods is still a period?

Implication of namely

How badly should I try to prevent a user from XSSing themselves?

Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?

Am I breaking OOP practice with this architecture?



Docker container cannot copy file into volume


How is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCopying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repositoryFrom inside of a Docker container, how do I connect to the localhost of the machine?What is the difference between the `COPY` and `ADD` commands in a Dockerfile?













1















I am pretty new to docker, so i might be doing something truly wrong



I need to share some files between docker containers, using a docker compose file



I have already created a volume like this



docker volume create shared


After that i can check the created volume



docker volume inspect shared
[

"CreatedAt": "2019-03-08T14:54:57-05:00",
"Driver": "local",
"Labels": ,
"Mountpoint": "/var/lib/docker/volumes/shared/_data",
"Name": "shared",
"Options": ,
"Scope": "local"

]


My docker-compose.yaml file looks like this



version: '3.1'

services:
service1:
build:
context: Service1
dockerfile: Dockerfile
restart: always
container_name: server1-server
volumes:
- shared:/shared

service2:
build:
context: Service2
dockerfile: Dockerfile
restart: always
container_name: server2-server
volumes:
- shared:/shared

volumes:
shared:
external: true


And the Dockerfile looks like this (just for testing purposes)



FROM microsoft/dotnet:2.2-sdk AS build-env

RUN echo "test" > /shared/test.info


When i issue a docker-compose up command i get this error



/bin/sh: 1: cannot create /shared/test.info: Directory nonexistent


If i modify the Dockerfile to this



FROM microsoft/dotnet:2.2-sdk AS build-env

WORKDIR /app

COPY *.csproj ./
RUN cp *.csproj /shared/


I get this error



cp: cannot create regular file '/shared/': Not a directory


Any ideas how to achieve this ?










share|improve this question
























  • RUN mkdir /shared?

    – Max♦
    Mar 8 at 20:47












  • Thanks a lot @Max, that helped with the writing part; but now i need to read that stored data in another container; what should i do ? RUN mount or something ? because in the second container the problem is that i cannot mkdir the same directory

    – jmiguel77
    Mar 8 at 21:01












  • Could you expand your docker-compose.yml to include the second service?

    – Max♦
    Mar 8 at 21:08











  • i edited the original post to reflect the second service, the second Dockerfile uses the same image and only does a RUN ls -ln /shared but /shared does not exists

    – jmiguel77
    Mar 8 at 21:12











  • i finally decided against my first approach and now am building the dependencies for the service in the same image, as a previous step to build the main application; this question should be closed now

    – jmiguel77
    Mar 11 at 15:14
















1















I am pretty new to docker, so i might be doing something truly wrong



I need to share some files between docker containers, using a docker compose file



I have already created a volume like this



docker volume create shared


After that i can check the created volume



docker volume inspect shared
[

"CreatedAt": "2019-03-08T14:54:57-05:00",
"Driver": "local",
"Labels": ,
"Mountpoint": "/var/lib/docker/volumes/shared/_data",
"Name": "shared",
"Options": ,
"Scope": "local"

]


My docker-compose.yaml file looks like this



version: '3.1'

services:
service1:
build:
context: Service1
dockerfile: Dockerfile
restart: always
container_name: server1-server
volumes:
- shared:/shared

service2:
build:
context: Service2
dockerfile: Dockerfile
restart: always
container_name: server2-server
volumes:
- shared:/shared

volumes:
shared:
external: true


And the Dockerfile looks like this (just for testing purposes)



FROM microsoft/dotnet:2.2-sdk AS build-env

RUN echo "test" > /shared/test.info


When i issue a docker-compose up command i get this error



/bin/sh: 1: cannot create /shared/test.info: Directory nonexistent


If i modify the Dockerfile to this



FROM microsoft/dotnet:2.2-sdk AS build-env

WORKDIR /app

COPY *.csproj ./
RUN cp *.csproj /shared/


I get this error



cp: cannot create regular file '/shared/': Not a directory


Any ideas how to achieve this ?










share|improve this question
























  • RUN mkdir /shared?

    – Max♦
    Mar 8 at 20:47












  • Thanks a lot @Max, that helped with the writing part; but now i need to read that stored data in another container; what should i do ? RUN mount or something ? because in the second container the problem is that i cannot mkdir the same directory

    – jmiguel77
    Mar 8 at 21:01












  • Could you expand your docker-compose.yml to include the second service?

    – Max♦
    Mar 8 at 21:08











  • i edited the original post to reflect the second service, the second Dockerfile uses the same image and only does a RUN ls -ln /shared but /shared does not exists

    – jmiguel77
    Mar 8 at 21:12











  • i finally decided against my first approach and now am building the dependencies for the service in the same image, as a previous step to build the main application; this question should be closed now

    – jmiguel77
    Mar 11 at 15:14














1












1








1








I am pretty new to docker, so i might be doing something truly wrong



I need to share some files between docker containers, using a docker compose file



I have already created a volume like this



docker volume create shared


After that i can check the created volume



docker volume inspect shared
[

"CreatedAt": "2019-03-08T14:54:57-05:00",
"Driver": "local",
"Labels": ,
"Mountpoint": "/var/lib/docker/volumes/shared/_data",
"Name": "shared",
"Options": ,
"Scope": "local"

]


My docker-compose.yaml file looks like this



version: '3.1'

services:
service1:
build:
context: Service1
dockerfile: Dockerfile
restart: always
container_name: server1-server
volumes:
- shared:/shared

service2:
build:
context: Service2
dockerfile: Dockerfile
restart: always
container_name: server2-server
volumes:
- shared:/shared

volumes:
shared:
external: true


And the Dockerfile looks like this (just for testing purposes)



FROM microsoft/dotnet:2.2-sdk AS build-env

RUN echo "test" > /shared/test.info


When i issue a docker-compose up command i get this error



/bin/sh: 1: cannot create /shared/test.info: Directory nonexistent


If i modify the Dockerfile to this



FROM microsoft/dotnet:2.2-sdk AS build-env

WORKDIR /app

COPY *.csproj ./
RUN cp *.csproj /shared/


I get this error



cp: cannot create regular file '/shared/': Not a directory


Any ideas how to achieve this ?










share|improve this question
















I am pretty new to docker, so i might be doing something truly wrong



I need to share some files between docker containers, using a docker compose file



I have already created a volume like this



docker volume create shared


After that i can check the created volume



docker volume inspect shared
[

"CreatedAt": "2019-03-08T14:54:57-05:00",
"Driver": "local",
"Labels": ,
"Mountpoint": "/var/lib/docker/volumes/shared/_data",
"Name": "shared",
"Options": ,
"Scope": "local"

]


My docker-compose.yaml file looks like this



version: '3.1'

services:
service1:
build:
context: Service1
dockerfile: Dockerfile
restart: always
container_name: server1-server
volumes:
- shared:/shared

service2:
build:
context: Service2
dockerfile: Dockerfile
restart: always
container_name: server2-server
volumes:
- shared:/shared

volumes:
shared:
external: true


And the Dockerfile looks like this (just for testing purposes)



FROM microsoft/dotnet:2.2-sdk AS build-env

RUN echo "test" > /shared/test.info


When i issue a docker-compose up command i get this error



/bin/sh: 1: cannot create /shared/test.info: Directory nonexistent


If i modify the Dockerfile to this



FROM microsoft/dotnet:2.2-sdk AS build-env

WORKDIR /app

COPY *.csproj ./
RUN cp *.csproj /shared/


I get this error



cp: cannot create regular file '/shared/': Not a directory


Any ideas how to achieve this ?







docker docker-volume






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 21:10







jmiguel77

















asked Mar 8 at 20:43









jmiguel77jmiguel77

485412




485412












  • RUN mkdir /shared?

    – Max♦
    Mar 8 at 20:47












  • Thanks a lot @Max, that helped with the writing part; but now i need to read that stored data in another container; what should i do ? RUN mount or something ? because in the second container the problem is that i cannot mkdir the same directory

    – jmiguel77
    Mar 8 at 21:01












  • Could you expand your docker-compose.yml to include the second service?

    – Max♦
    Mar 8 at 21:08











  • i edited the original post to reflect the second service, the second Dockerfile uses the same image and only does a RUN ls -ln /shared but /shared does not exists

    – jmiguel77
    Mar 8 at 21:12











  • i finally decided against my first approach and now am building the dependencies for the service in the same image, as a previous step to build the main application; this question should be closed now

    – jmiguel77
    Mar 11 at 15:14


















  • RUN mkdir /shared?

    – Max♦
    Mar 8 at 20:47












  • Thanks a lot @Max, that helped with the writing part; but now i need to read that stored data in another container; what should i do ? RUN mount or something ? because in the second container the problem is that i cannot mkdir the same directory

    – jmiguel77
    Mar 8 at 21:01












  • Could you expand your docker-compose.yml to include the second service?

    – Max♦
    Mar 8 at 21:08











  • i edited the original post to reflect the second service, the second Dockerfile uses the same image and only does a RUN ls -ln /shared but /shared does not exists

    – jmiguel77
    Mar 8 at 21:12











  • i finally decided against my first approach and now am building the dependencies for the service in the same image, as a previous step to build the main application; this question should be closed now

    – jmiguel77
    Mar 11 at 15:14

















RUN mkdir /shared?

– Max♦
Mar 8 at 20:47






RUN mkdir /shared?

– Max♦
Mar 8 at 20:47














Thanks a lot @Max, that helped with the writing part; but now i need to read that stored data in another container; what should i do ? RUN mount or something ? because in the second container the problem is that i cannot mkdir the same directory

– jmiguel77
Mar 8 at 21:01






Thanks a lot @Max, that helped with the writing part; but now i need to read that stored data in another container; what should i do ? RUN mount or something ? because in the second container the problem is that i cannot mkdir the same directory

– jmiguel77
Mar 8 at 21:01














Could you expand your docker-compose.yml to include the second service?

– Max♦
Mar 8 at 21:08





Could you expand your docker-compose.yml to include the second service?

– Max♦
Mar 8 at 21:08













i edited the original post to reflect the second service, the second Dockerfile uses the same image and only does a RUN ls -ln /shared but /shared does not exists

– jmiguel77
Mar 8 at 21:12





i edited the original post to reflect the second service, the second Dockerfile uses the same image and only does a RUN ls -ln /shared but /shared does not exists

– jmiguel77
Mar 8 at 21:12













i finally decided against my first approach and now am building the dependencies for the service in the same image, as a previous step to build the main application; this question should be closed now

– jmiguel77
Mar 11 at 15:14






i finally decided against my first approach and now am building the dependencies for the service in the same image, as a previous step to build the main application; this question should be closed now

– jmiguel77
Mar 11 at 15:14













1 Answer
1






active

oldest

votes


















2














A Dockerfile contains instructions to create an image. After the image is built, the image can be run as a container.



A volume is attached when launching containers.



It thus makes no sense to use Dockerfile instructions to copy a file into a volume while building an image.



Volumes are generally used to share runtime data between containers, or to keep data after a container is stopped.






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



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070725%2fdocker-container-cannot-copy-file-into-volume%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









    2














    A Dockerfile contains instructions to create an image. After the image is built, the image can be run as a container.



    A volume is attached when launching containers.



    It thus makes no sense to use Dockerfile instructions to copy a file into a volume while building an image.



    Volumes are generally used to share runtime data between containers, or to keep data after a container is stopped.






    share|improve this answer



























      2














      A Dockerfile contains instructions to create an image. After the image is built, the image can be run as a container.



      A volume is attached when launching containers.



      It thus makes no sense to use Dockerfile instructions to copy a file into a volume while building an image.



      Volumes are generally used to share runtime data between containers, or to keep data after a container is stopped.






      share|improve this answer

























        2












        2








        2







        A Dockerfile contains instructions to create an image. After the image is built, the image can be run as a container.



        A volume is attached when launching containers.



        It thus makes no sense to use Dockerfile instructions to copy a file into a volume while building an image.



        Volumes are generally used to share runtime data between containers, or to keep data after a container is stopped.






        share|improve this answer













        A Dockerfile contains instructions to create an image. After the image is built, the image can be run as a container.



        A volume is attached when launching containers.



        It thus makes no sense to use Dockerfile instructions to copy a file into a volume while building an image.



        Volumes are generally used to share runtime data between containers, or to keep data after a container is stopped.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 21:45









        Boris van KatwijkBoris van Katwijk

        1,05211022




        1,05211022





























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070725%2fdocker-container-cannot-copy-file-into-volume%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







            Popular posts from this blog

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page