Application in Docker container does not save file to docker volume

1.5k Views Asked by At

I am using Docker desktop to develop my application. I have created a "uploadedfiles" docker volume and I am trying to save files to it, from my docker application. When I save a file from my docker application, I see that the file is saved to the "uploadedfiles" folder on my docker container. I am therefore assuming that I am not binding my application container to the created volume in my Dockerfile.Is my assumption correct?

How can I bind my application container to the created volume in my Dockerfile?

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base

WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["InstaTranscribeServerSide/InstaTranscribeServerSide.csproj", "InstaTranscribeServerSide/"]
COPY ["Services/Services.csproj", "Services/"]
COPY ["DataAccess/DataAccess.csproj", "DataAccess/"]
RUN dotnet restore "InstaTranscribeServerSide/InstaTranscribeServerSide.csproj"
COPY . .
WORKDIR "/src/InstaTranscribeServerSide"
RUN dotnet build "InstaTranscribeServerSide.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "InstaTranscribeServerSide.csproj" -c Release -o /app/publish

FROM base AS final
VOLUME CREATE uploadedfiles
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "InstaTranscribeServerSide.dll"]

Docker Volume does not show uploaded files

Docker Volume does not show uploaded files

Container shows that the volume was not "bound"

Container shows that the volume was not "bound"

Container shows file was uploaded to "uploadedfiles" folder on container: Container shows file was uploaded to "uploadedfiles" folder on container

1

There are 1 best solutions below

0
On

I have successfully mount /home/ folder of my host to the /mnt folder of the existing (not running) container. You can do it in the following way:

Open configuration file corresponding to the stopped container, which can be found at /var/lib/docker/containers/99d...1fb/config.v2.json (may be config.json for older versions of docker).

Find MountPoints section, which was empty in my case: "MountPoints":{}. Next replace the contents with something like this (you can copy proper contents from another container with proper settings):

"MountPoints":{"/mnt":{"Source":"/home/<user-name>","Destination":"/mnt","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/home/<user-name>","Target":"/mnt"},"SkipMountpointCreation":false}}
or the same (formatted):

  "MountPoints": {
    "/mnt": {
      "Source": "/home/<user-name>",
      "Destination": "/mnt",
      "RW": true,
      "Name": "",
      "Driver": "",
      "Type": "bind",
      "Propagation": "rprivate",
      "Spec": {
        "Type": "bind",
        "Source": "/home/<user-name>",
        "Target": "/mnt"
      },
      "SkipMountpointCreation": false
    }
  }

Restart the docker service: service docker restart This works for me with Ubuntu 18.04.1 and Docker 18.09.0