Is it possible to share Java objects directly through shared memory from a host to a local Docker container? If so, how?
Thus, from code running in a JVM J1, I’d like to run a Docker container locally (meaning on the same physical machine), sharing the host memory with the client container. In the client container, I’d run a JVM J2. I want now for Java instances living in J1 to be accessible from J2.
Here is a strategy that I thought about.
- Creating the local Docker container from J1 seems easy enough using e.g. docker-java.
Sharing memory seems feasible thanks to Docker mechanisms. - Using FFM I could allocate a shared memory segment in J1 and access it from J2.
- One thing that I ignore is whether J2 will indeed be able to access that memory segment as if J2 was not containerized, in other words, whether it is possible to let Docker share the memory in a way that will be transparent to the client code (meaning the processes running in the container), or whether it is necessary for the client code to use some special memory allocation mechanism (such as shmget?) to access the shared memory. In the latter case, can I somehow tell the JVM in J2 to use that special memory allocation mechanism to access the shared memory segment?
Note that (I think that) the above strategy turns the question into: is it possible to use FFM across container boundaries?
The reason I want to do this is to run untrusted code from the container, while allowing for easy (meaning requiring no serialization code) communication of some results between the container and the host.