Advertise with ErnesTech.comClick to Watch Video

How to Bind an External Folder located on the Host Computer to Docker Container with --noCopy flag using docker-compose.yaml file


How to Bind an External Folder located on the Host Computer to Docker Container with --noCopy flag using docker-compose.yaml file

Problem: Invalid mount config for type "bind": field VolumeOptions must not be specified

[NB] This will save you a lot of time of research and reading: If you want to bind a folder with content located on a different computer (Lets say a File Server) to a Docker Container without copying all the files from the source folder to a Docker Container folder, see below:


Solution: Make sure that you are using docker-compose version 3.2 at the moment and inside the defined Services create a volume section see the code below:

Services:
     WebService:
            Image: yourImageGoesHere
            Build: yourBuildConfigurationGoesHere
            enviroment: 
                 - YourEnviromentConfigurationComesInHere
            restart: always # If you want the container to restart automatically after failure
            volumes:
                - type: volume
                   source: mydata #Make sure that this section references defined in the volume top level
                   target: /app/folderInsideYourDockerContainer #Make sure that this section matches the folder you want to bind the directory to inside docker container
                   volume:  #the fun part begins
                        nocopy: true #This part is crucial to making sure that the files don't get copied to Docker container. This is important when you deal with big data
                -  type: bind #this part is very important to specify because "bind" allows other app to change files inside the source directory
                    source: /folderYouWantAllFilesToComeFrom/subfolder
                    target: /app/folderInsideYourDockerContainer  #As specified above 

#This part is very important, you will have specify the Volume Section (this is called top level because of space)
volumes:
    mydata: {} # Notice the "{}" it has to be there or else you will see an error. 

[Update] If the above does not work or if you don't see a volume mounted in Docker Container with files in it, the work around it is to specify volumes like below: 

volumes:
    - type: bind
       source: /specifyTheSourceHere
       target: /pathInsideDockerContainer

- If the bind is successful, there is no need to copy all the files when the source directory has new files, Docker will sync the files to the Docker Container directory specified in target directive.






© 2024 - ErnesTech - Privacy
E-Commerce Return Policy