My container creates fifo pipe in the bind mounted dir but container when reads or writes to this pipe, the host cant receive it or vice versa. with similar permissions to create or open pipe works for communication within host and within container. But it does not work in between host and container.
The pipe is created and reads/writes in cpp program within container. Pipe created with both 666 and 777 permissions and opened with O_RDWR. Similar cpp programs reads/writes in the host. Again these program works fine within container and within host the problem happens only in host communication.
docker run -it --name broken-container -v /tmp:/app2 cppdocker
After reading your comments in response to questions from other users, I suspect you're running into the issue that the file permissions you supply to
mknod()(orcreat()/mkdir()when creating regular files / directories) are still masked by your process's umask. Combine that with the fact docker runs the containers under a different user than the user you're using from the outside, you're likely running into a "permission denied" situation.Other than "does not work" you didn't post any error message, and the example code you are using doesn't contain any error checking of the system calls you are using. Always check for errors when calling operating system functions! Even so, you'd have noticed the failures had you run your programs through
strace, which would give you some feedback as to which operations fail.Assuming that my guess here is correct and you are really running into actual permission problems due to the umask, I've taken the example code you've posted and changed three things:
read()andwrite()system calls to properly handle theEINTRcorner case, as well as thewrite()system call to loop until all bytes have been written. (This is considered best practice when using blocking reads/writes.)0777. (I would recommend to do this over changing theumaskof the process, though you could also do that before callingmknod.)Your receiver code adjusted:
Your sender code adjusted:
Running this on my system with a standard Docker container (no customization) works.
And if my guess is wrong and it's not the
umaskyou'll at least get a proper error message why the operation failed.