Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy files generated inside docker container to local host through docker-compose [duplicate]

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!!!

like image 689
Mohammad Saad Avatar asked Oct 25 '25 04:10

Mohammad Saad


1 Answers

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

like image 87
Nijo Avatar answered Oct 27 '25 19:10

Nijo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!