I am using a Dockerfile with a docker-compose.yml file, and I have created two bind mounts. My understanding is that bind mounts map to the host file system, and that all files on the host filesystem should be visible and usable in the container via the bind mount. But that’s not happening.
In my Dockerfile I have these two lines:
VOLUME /test-data
VOLUME /nasm-data
In my docker-compose.yml file I create the bind mounts:
version: “3.8”
services:
srv1:
volumes:
- type: bind
source: /opt/Test_Data/
target: /test-data
- type: bind
source: /opt/P01_SH/Complex_Calc_YZ/
target: /nasm-data
build:
context: /opt/P01_SH/Dockerfiles/
dockerfile: /opt/P01_SH/Dockerfiles/Dockerfile
volumes:
test-data:
nasm-data:
After I build these, I log onto the container’s command line. Both bind mount directories are there (cd /test-data). The bind mount “test-data” should be able to see and open the file “testfile.txt” in its source directory, but:
cd /test-data
cat testfile.txt
cat: testfile.txt: No such file or directory
The same thing happens with the bind mount “nasm-data.” The file in its source folder is not found.
So my questions are:
-
Am I correct that a bind mount should be able to open and read files from the host filesystem mapped as its source?
-
Is my procedure for creating the bind mounts, shown in the code above, correct?
-
How can I correct this so the container can use host system files?
Thanks very much.