Search code examples
dockerunixdocker-composemountmounted-volumes

Docker volume mount issue to a mounted folder


We have mounted a folder in a Linux machine to our docker container application using (docker-compose) volumes: - /mnt/share:/mnt/share

The /mnt/share is a mounted folder in the machine(Not a real folder in the machine, its our file server). IF for some reason that mount is lost and then remounted again. The application running in the docker container is not having access to the mounted folder until the container is restarted.


Solution

  • The following solution helped me to continue. I wrote a script to check whether the folder exists. The script is then called a command in the docker-compose file.

       version:"3" 
      services:
       flowable-task-handler:
        build: flowable-task-handler  
        ports:
        - "8085:8085"
        command: bash -c "/wait_for_file_mount.sh /mnt/share/fileshares/ && java -jar /app.jar"
    

    wait_for_file_mount.sh

    #!/bin/sh
    # Used to check whether the mount folder is ready for flowable to use
    mountedfolder="$1"
    until [  -d "$mountedfolder" ];
     do sleep 2;
      echo error "Mounted folder not found : $mountedfolder";
       done;
    

    Its a spring boot application. I have removed the entrypoint in the DockerFile and application is started using the command in docker compose(java -jar /app.jar")