Docker Community Forums

Share and learn in the Docker community.

Docker compose volumes question


(Tim Uckun) #1

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?


(Sam) #2

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.


(Tim Uckun) #3

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


(Sam) #4

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