How to store uploaded files on the host when using Dockerfile/docker-compose

Hi,
I am using the following docker-compose.yaml to deploy my app, but could not figure out how to mount a volume for storing the uploaded files, because when checking the release folder i see ./lib/my-app-0.1.0/priv/static/uploads, any time the app version changes the path changes.
How to deal with this situation? or is there a better way?
Please help

version: '3.6'

services:
  db:
    image: "postgres:15-alpine"
    restart: always
    environment:
      POSTGRES_USER: xxx
      POSTGRES_PASSWORD: yyy
    volumes:
      - "~/.pgdata:/var/lib/postgresql/data"
    ports:
      - "5432:5432"

  app:
    build: 
      context: .
    ports:
      - 4000:4000
    depends_on:
      - db
    restart: always
    environment:
      DATABASE_URL: "ecto://xxxxx" 
      SECRET_KEY_BASE: "5hxxxxni"

How about mounting a volume at some fixed location (such as /uploads) and have your app store files there?

1 Like

I will try it, then let you know

It works
This is what I have done

# endpoint.ex

  plug Plug.Static,
    at: "/uploads",
    from: Application.compile_env(:my_app, :uploads_dir),
    gzip: false


# config/config.exs
config :my_app,
  ecto_repos: [MyApp.Repo],
  uploads_dir: "/uploads"
# Dockerfile
# changes made to the file

WORKDIR "/app"
#  to fix permission denied, I use UID, and GID of the host
RUN chown ${UID}:${GID} /app

#  to fix permission denied
USER ${UID}
# docker-compose.yaml

app:
    build: 
      context: .
 # ... other fields
    volumes:
      - "~/apps/my-app/uploads:/uploads"
#... other fields ...
      

@trisolaran Thank you so much for your help.