Docker-DCO-1.1-Signed-off-by: Tom Fotherby <github@tomfotherby.com> (github: tomfotherby)
| ... | ... |
@@ -71,6 +71,21 @@ read-only. |
| 71 | 71 |
Here we've mounted the same `/src/webapp` directory but we've added the `ro` |
| 72 | 72 |
option to specify that the mount should be read-only. |
| 73 | 73 |
|
| 74 |
+### Mount a Host File as a Data Volume |
|
| 75 |
+ |
|
| 76 |
+As well as directories, the `-v` flag can be used to mount a single file from the host into a container. |
|
| 77 |
+ |
|
| 78 |
+ $ sudo docker run --rm -it -v ~/.bash_history:/.bash_history ubuntu /bin/bash |
|
| 79 |
+ |
|
| 80 |
+This will drop you into a bash shell in a new container, you will have your bash history from your host and when |
|
| 81 |
+you exit the container the host will have the history of the commands typed while in the container. |
|
| 82 |
+ |
|
| 83 |
+> **Note:** |
|
| 84 |
+> The two-way binding of the mounted file will only be preserved as long as the inode doesn't change. Many |
|
| 85 |
+> tools used to edit files including `vi` and `sed --in-place` may result in a inode change. In the case where you |
|
| 86 |
+> want to edit the file, it is often best to mount the parent directory. |
|
| 87 |
+ |
|
| 88 |
+ |
|
| 74 | 89 |
## Creating and mounting a Data Volume Container |
| 75 | 90 |
|
| 76 | 91 |
If you have some persistent data that you want to share between |