Comunication between Host and Docker Containner using FIFO pipes by bind mount (Linux) #45758
shamirtahir50
started this conversation in
General
Replies: 1 comment 3 replies
-
What platform are you running on? Is this on Linux, are you running Docker Desktop? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My container creates fifo pipe in the bind mounted dir but container when reads or writes to this pipe, the host cant recieve it or vice versa. with similar permissions to create or open pipe works for comunication within host and within containner. But it does not work in between host and containner.
The pipe is created and reads/writes in cpp program within containeer. Pipe created with both 666 and 777 permisssions and opened with O_RDWR. Simmilar cpp programs reads/writes in the host. Again these program works fine within containner and within host the problem happens only in host communication.
docker run -it --name broken-container -v /tmp:/app2 cppdocker
send.cpp Dockerfile just compiles it.
#include #include #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> int main() { int fd; const char* pipeName = "/app2/my_pipe"; // Pipe file path fd = open(pipeName, O_RDWR); char * message = "hello"; int check = write(fd, message, strlen(message) + 1); close(fd); return 0; }
recieve.cpp runs on host
#include #include #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> int main() { const char* pipeName = "/tmp/my_pipe"; int val = mkfifo(pipeName, 0777); char buffer[80]; int fd = open(pipeName, O_RDWR); ssize_t bytesRead = read(fd, buffer, sizeof(buffer) - 1); buffer[bytesRead] = '\0'; close(fd); std::cout << "Received message: " << buffer << std::endl; return 0; }
Beta Was this translation helpful? Give feedback.
All reactions