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

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived