How to dockerize and application that spawns many processes?

  Kiến thức lập trình

I have an application from a vendor, which consists of a bunch of binaries and I need to dockerize it for our development lab environment. The application is built such that an “entrypoint” binary launches all those other binaries and exits.

This application’s architecture is such that it has a single binary “entrypoint”, which creates a shared memory file and launches a bunch of processes that use this file, and then exits. So it cannot be used as the docker process and it can’t be used with any kind of init system because it does not fork those other processes, but rather just launches them somehow (maybe via shell or smth, I have no idea).

And when you want to shut everything down, you need to call that entrypoint binary again so it would clean up the shared memory file and kill the processes it launched.

Also, this architecture means that instead of outputting everything to stdout, all those processes write logs to a specific file. As a result I can’t track the logs either. I tried to ln -sf /proc/1/fd/1 /app/log/app.log in the docker image but it doesn’t seem to do anything.

I tried to make the following entrypoint but it doesn’t work and just hangs there, never exiting:

#!/bin/bash

set -x
dbus-daemon --system --print-address

trap "/opt/app/entrypoint --terminate; exit" 0 SIGINT

su -s /bin/bash app -c "/opt/app/entrypoint $@"
# now it would launch the processes and exit
tail -f /opt/app/logs/app.log

Is there any way that such an application can be containerized or should I reach out to the vendor to change it somehow?

LEAVE A COMMENT