Bind mount docker compose

Hello! I am not being able to create a bind mount so all of my containers can save here and also access it, as well as outside of docker. I have tried different ways to create it but when I run my containers, nothing is being saved in the location I want.
The location is ‘storage-spooler’, this folder is inside another folder where I have my docker-compose.yml since I have read that it has to be in the same location as the .yml (if not please let me know so I can move it one folder outside :slight_smile: )

Docker compose:

version: '3.8'

x-resource-limits: &resource-limits
  deploy:
    resources:
      limits:
          memory: ${MAX_RAM}
          cpus : ${MAX_CPU}
      # reservations:

services:
  main_service:
    build:
      context: ../
      dockerfile: ./service_containers/main_service/Dockerfile
    stop_grace_period: 50s
    restart: always
    stdin_open: true
    tty: true
    network_mode: "host"
    volumes:
      # - ./storage-spooler:${PATH_TO_STORAGE_SPOOLER}
      - ./storage-spooler:/home/y3qucfm/workspace/ods/system_controller/storage-spooler
    env_file:
      - ./.env
    <<: *resource-limits

  can_logger_service:
    build:
      context: ../
      dockerfile: ./service_containers/can_logger_service/Dockerfile
    network_mode: "host"
    stop_grace_period: 50s
    restart: always
    stdin_open: true
    tty: true
    volumes:
      # - ./storage-spooler:${PATH_TO_STORAGE_SPOOLER}
      - ./storage-spooler:/home/y3qucfm/workspace/ods/system_controller/storage-spooler

    env_file:
      - ./.env
    <<: *resource-limits

  monitor_data_service:
    build:
      context: ../
      dockerfile: ./service_containers/monitor_data_service/Dockerfile
    network_mode: "host"
    restart: always
    stop_grace_period: 50s
    stdin_open: true
    tty: true
    volumes:
      # - ./storage-spooler:${PATH_TO_STORAGE_SPOOLER}
      - ./storage-spooler:/home/y3qucfm/workspace/ods/system_controller/storage-spooler
    env_file:
      - ./.env
    <<: *resource-limits

I am creating a file in my can_logger_service ( outside the folder where I have my .yml → ./service_containers/can_logger_service) container with a python script:

            self.log_file = open(f'{self.path_to_spooler}/log_file.asc', 'w')
            print(f"File opened: {self.log_file}")

where my path_to_storage_spooler is a .env variable:
PATH_TO_STORAGE_SPOOLER=/home/y3qucfm/workspace/ods/system_controller/storage-spooler

To resume everything, I want to be able to stare my files in the “storage-spooler” inside system_controllers. My docker-compose.yml gets the dockerfiles the folders in ./service_containers
I have tried to modify in lots of ways my docker compose but nothing seems to be working! please help! thank you!

Your compose file looks right.

I am not sure what this post is about, as you neither shared an exact error message, nor described the actual behavior.

Are your paths set correctly, the ones your application uses inside your container?

You can probably go into one of your containers with docker exec -it <c-id> sh and try to create a file ls > /path/test.txt.

I don’t get any error messages, my application has no problem creating and opening the file but on the location I have (storage spooler) nothing is being saved, I get that the file was opened but as I mentioned, my storage-spooler folder is empty
image

nothing is being created :frowning: when I exec onto the container I dont have any location pointing to the bind mount, eventhough I dont know if there should be a bind mount folder
this is one of my containers

Please exec into one of the containers of the compose project and create a file in /home/y3qucfm/workspace/ods/system_controller/storage-spooler and then exec into another container of your project, if the file is visible in /home/y3qucfm/workspace/ods/system_controller/storage-spooler.