Can docker port forward to a unix file socket on the host container?

Docker’s -p syntax won’t take a unix socket: -p=[] : Publish a container᾿s port to the host (format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort) One solution would be to: Run your container without any -p specification, we’ll name it “cont1” (–name cont1) Run a second container which: Bind mounts the unix socket (-v /tmp/file.sock:/tmp/file.sock) to have … Read more

How to create Unix Domain Socket with a specific permissions in C?

Another solution is to create a directory with the desired permissions, and then create the socket inside it (example code without any regard for error checking and buffer overflows): // Create a directory with the proper permissions mkdir(path, 0700); // Append the name of the socket strcat(path, “/socket_name”); // Create the socket normally sockaddr_un address; … Read more

What are the differences from running PHP-FPM over an Unix Socket vs a TCP/IP Socket?

The difference is mainly the added overhead of using the full network stack to “pack” and “unpack” every piece of data. Mind you that the overhead is negligible for most deployments Using a socket (e.g. listen = ‘/tmp/php-fpm.sock’) makes sense when both the front-end (e.g. Nginx) and php-fpm are in the same box and You … Read more

Unix Domain Socket: Using datagram communication between one server process and several client processes

There’s a trick to using Unix Domain Socket with datagram configuration. Unlike stream sockets (tcp or unix domain socket), datagram sockets need endpoints defined for both the server AND the client. When one establishes a connection in stream sockets, an endpoint for the client is implicitly created by the operating system. Whether this corresponds to … Read more

htons() function in socket programing

It has to do with the order in which bytes are stored in memory. The decimal number 5001 is 0x1389 in hexadecimal, so the bytes involved are 0x13 and 0x89. Many devices store numbers in little-endian format, meaning that the least significant byte comes first. So in this particular example it means that in memory … Read more