1

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! But that is a bummer. Maybe I need to change my mind about docker, but, as I said, I thought it is meant to be used in a one-service-per-container manner, so that you can easily switch out/update services, without breaking a complete container. I guess one other solution would be some kind of docker-in-docker approach, where the main service is run in the host container (php-fpm) and can call the services of subcontainers (wkhtmltopdf, etc.).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.