Tek
Tek

Reputation: 499

Docker - inter-container script execution

currently my web application is running on a server, where all the services (nginx, php, etc.) are installed directly in the host system. Now I wanted to use docker to separate these different services into specific containers. Nginx and php-fpm are working fine. But in the web application pdfs can be generated, which is done using wkhtmltopdf and as I want to follow the single-service-per-container pattern, I want to add an additional container which houses wkhtmltopdf and takes care of this specific service. The problem is: how can I do that? How can I call the wkhtmltopdf binary from the php-fpm container?

One solution is to share the docker.socket, but that is a big security flaw, so I really don‘t like to it.

So, is there any other way to achieve this? And isn‘t this "microservice separation" one of the main purposes/goals of docker?

Thanks for your help!

Upvotes: 1

Views: 58

Answers (1)

David Maze
David Maze

Reputation: 158714

You can't directly call binaries from one container to another. ("Filesystem isolation" is also a main goal of Docker.)

In this particular case, you might consider "generate a PDF" as an action your service takes and not a separate service in itself, and so executing the binary as a subprocess is a means to an end. This doesn't even raise any complications since presumably mkhtmltopdf isn't a long-running process, you'll launch it once per request and not respond until the subprocess runs to completion. I'd install or include it in the Dockerfile that packages your PHP application, and be architecturally content with that.

Otherwise the main communication between containers is via network I/O and so you'd have to wrap this process in a simple network protocol, probably a minimal HTTP service in your choice of language/framework. That's probably not worth it for this, but it's how you'd turn this binary into "a separate service" that you'd package and run as a separate container.

Upvotes: 1

Related Questions