Docker container cannot copy file into volume Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!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?

How to play a character with a disability or mental disorder without being offensive?

Crossing US/Canada Border for less than 24 hours

What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?

What is this clumpy 20-30cm high yellow-flowered plant?

How could we fake a moon landing now?

What does it mean that physics no longer uses mechanical models to describe phenomena?

Putting class ranking in CV, but against dept guidelines

Can a new player join a group only when a new campaign starts?

How to react to hostile behavior from a senior developer?

Can the Great Weapon Master feat's damage bonus and accuracy penalty apply to attacks from the Spiritual Weapon spell?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

Do I really need to have a message in a novel to appeal to readers?

How come Sam didn't become Lord of Horn Hill?

Why do we bend a book to keep it straight?

Illegal assignment from sObject to Id

Taylor expansion of ln(1-x)

How to write this math term? with cases it isn't working

ArcGIS Pro Python arcpy.CreatePersonalGDB_management

Amount of permutations on an NxNxN Rubik's Cube

Question about debouncing - delay of state change

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

How to compare two different files line by line in unix?

Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?

What order were files/directories outputted in dir?



Docker container cannot copy file into volume



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!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?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








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

495412




495412












  • 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,05711122




        1,05711122





























            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

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved