4

I have an app which will create a directory storage inside the docker container and store generated files there. I would like these files & sub-folders (inside the storage directory) to get copied to the host directory test.

The directory of the container:

# sudo docker exec -it eajcdfufh /bin/bash
root#eajcdfufh:~# ls
storage
root#eajcdfufh:~ cd storage
folder1        file1

To achieve this operation, I have tried to key in volumes params but unfortunately nothing gets copied to local directory.

docker-compose.yml

version: "3.9"
services:
  app:
    build: 
        context: ./
    volumes:
        - /home/test:/root/storage
    ports:
        - "8000:8000"
   
  nginx:
    restart: always
    build:
        context: ./nginx
    ports:
      - "80:80"
    depends_on:
      - app

May I ask why does nothing gets copied ? And how can I perform such operations?

Thanks, would highly appreciate the help!!!

Mohammad Saad
  • 1,935
  • 10
  • 28
  • 1
    Have you re-run `docker-compose up` since editing the `docker-compose.yml` file? If not, you'll need to do that before the mount will show up in the container. – Nick ODell Feb 08 '22 at 06:09
  • Compose on its own can't copy files; you need the imperative `docker cp` command (there does not appear to be a `docker-compose` wrapper for it). The volume mount you show should work, assuming the container `/root/storage` directory is the place the output is written; as @NickODell notes you'll have to restart the container (and lose the existing contents), and this will hide anything that was in the original image in that directory. Also consider running this program outside a container if you don't want Docker's filesystem isolation features. – David Maze Feb 08 '22 at 10:26

1 Answers1

2
version: "3.9"
services:
  app:
    build: 
    context: ./
    volumes:
    - ./test:/root/storage
    ports:
    - "8000:8000"
   
  nginx:
    restart: always
    build:
    context: ./nginx
    ports:
      - "80:80"
    depends_on:
      - app

This should work

Nijo
  • 772
  • 1
  • 8
  • 27