There's more...

In this recipe, we mounted a directory to the container. Similarly, we can also mount individual files to the container, as shown in the following code:

$ docker container run --rm 
-v $(HOME)/data_share/demo.txt:/demo.txt
ubuntu cat /demo.txt
data sharing demo

By default, when we mount a directory or a file into a container, it gets mounted in read–write mode, so that the container can alter the content of the mounted directory or file. We can prevent the containers from modifying the content of the mounted directory or file using the ro flag, as demonstrated in the following code:

$ touch file 
$ docker container run -rm
-v ${PWD}/file:/file:rw
ubuntu sh -c "echo rw mode >> /file"
$ cat file
rw mode
$ docker container run -rm
-v ${PWD}/file:/file:rw
ubuntu sh -c "echo ro >> /file"
sh: 1: cannot create /file: Read-only file system

Apparently, the write operation failed when we mounted the file as read-only.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.27.99