0

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

Ajit Goel
  • 4,180
  • 7
  • 59
  • 107
  • Volumes are bound to a container at *runtime*. How are you running the container? Have you tried to bind a volume to it? There's plenty of information on how to do that on the web and SO. – JohnXF Jan 05 '22 at 08:19
  • I am using Caprover to run the container, I have checked and Caprover has support for persistent apps, so I should be good. https://caprover.com/docs/persistent-apps.html – Ajit Goel Jan 05 '22 at 17:59

1 Answers1

0

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

Rakesh B E
  • 786
  • 4
  • 5