Docker compose volumes question

I have a compose file like this

volumes:
  postgres_data:
    driver: local
datacube_data:
   driver: local
 datacube_source:
   driver: local

services:
    datacube:
      container_name: datacube
    build:
      context: .
      dockerfile: Dockerfile.datacube
   # Keep the stdin open, so we can attach to our app container's process
   stdin_open: true
   # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
   tty: true

   depends_on:
     - db
   volumes:
     -  datacube_source:/root/Datacube

And I have a Dockerfile which starts like this

WORKDIR /root/Datacube

RUN ls -lah /root/Datacube

When I build this I get an error

ls: cannot access /root/Datacube: No such file or directory

Why isn’t this volume mounted?

because RUN (in the dockerfile) is executed at docker BUILD time, and the volume mapping happens at docker RUN time.
so, the volume does not exist yet.

So what’s the best way to populate that area with data?

use CMD or ENTRYPOINT to run a script just as the container starts, before the actual runtime command