I am trying to bind host dir to some dir inside container and expecting changes done inside container should reflect on host.
Here is the steps I have followed
created /hostdir on host and run ubuntu container in privileged mode
[root@nhbdlin03 ~]# mkdir /hostdir
[root@nhbdlin03 ~]# docker run -itd --privileged --name ubuntu -v /hostdir:/hostdir:z ubuntu
76aebded33274e95a6f569d0831aee4df27e9f200a8fd0401448239bd6f5bf80
[root@nhbdlin03 ~]# docker exec -it ubuntu bash
creating a container_dir inside container
root@76aebded3327:/# mkdir /container_dir
binding the two directory (successfull)
root@76aebded3327:/# mount --bind /container_dir /hostdir
creating a file named hello.txt inside /container_dir
root@76aebded3327:/# cd container_dir/
root@76aebded3327:/container_dir# touch hello.txt
its get reflected inside /hostdir as it is bind mount to /container_dir
root@76aebded3327:/container_dir# ls /hostdir/
hello.txt
exit container and check on host , is the same reflected
root@76aebded3327:/container_dir# exit
[root@nhbdlin03 ~]# ls /hostdir/
[root@nhbdlin03 ~]# ls /hostdir/ | wc -l
0
[root@nhbdlin03 ~]#
the content are not getting reflected.
I am missing something or doing completely wrong, please help me in the right direction.