title: Docker container cannot copy file into volume
body: <p>I am pretty new to docker, so i might be doing something truly wrong</p>
  
  <p>I need to share some files between docker containers, using a docker compose file</p>
  
  <p>I have already created a volume like this </p>
  
  <pre><code>docker volume create shared
  </code></pre>
  
  <p>After that i can check the created volume </p>
  
  <pre><code>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"
      }
  ]
  </code></pre>
  
  <p>My docker-compose.yaml file looks like this</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And the Dockerfile looks like this (just for testing purposes)</p>
  
  <pre><code>FROM microsoft/dotnet:2.2-sdk AS build-env
  
  RUN echo "test" &gt; /shared/test.info
  </code></pre>
  
  <p>When i issue a docker-compose up command i get this error</p>
  
  <pre><code>/bin/sh: 1: cannot create /shared/test.info: Directory nonexistent
  </code></pre>
  
  <p>If i modify the Dockerfile to this</p>
  
  <pre><code>FROM microsoft/dotnet:2.2-sdk AS build-env
  
  WORKDIR /app
  
  COPY *.csproj ./
  RUN cp *.csproj /shared/ 
  </code></pre>
  
  <p>I get this error </p>
  
  <pre><code>cp: cannot create regular file '/shared/': Not a directory
  </code></pre>
  
  <p>Any ideas how to achieve this ?</p>