Docker compose Volume - Uploaded files

Viewed 1103

I have a basic application runnig inside a docker container. The application is a page where users can upload files. The uploaded files are storing inside app/myApp/UploadedFiles (app folder is where the container installs my application)

If I restart the container I lost all files stored inside the folder app/myApp/UploadedFiles

What is the best approach to persist the uploaded files even if I restart the container?

I tried to use volumes inside my docker compose files;

volumes:
      - ${WEBAPP_STORAGE_HOME}/var/myFiles:/myApp/UploadedFiles

This creates a folder in the following root home>var>myFiles but if I upload files I never see them in these directory.

How can I do that?

My goal is to persists the files and could access to them and for example download the files.

Thanks

EDIT:

I created an App Service in Azure using Container Registry and this docker compose:

version: '2.0'

services:
  myWebSite:
    image: myWebSite.azurecr.io/myWebSite:latest    
    volumes:
      - ${WEBAPP_STORAGE_HOME}/var/myFiles:/myApp/UploadedFiles
    environment:
     - COMPOSE_CONVERT_WINDOWS_PATHS=1
    ports:
      - 5001:443 

If I upload a file in the web site the file goes to /myApp/UploadedFiles Using BASH I can go to /home/var/myFiles but there aren't any file inside.

I don't know if this is the correct approach. I can have the same problem with my application logs. I don't know how to read my logs.

1 Answers

Besides declaring the volume in the service you are using, you need to create another section in order to link in both ways the volume (from container to machine and from machine to pc)

Like this:

volumes:
      - database:/var/lib/postgresql/data
volumes:
  database:
Related