We have an existing java application which exposes a REST API. When it receives a http request, it starts another java process using the Runtime.getRuntime().exec.
We are in the process of migrating this application to docker and we would like to separate these services, the REST application in 1 container and the other component in another container.
Is there any way, that the REST application can start the other application in another docker container?
It is possible to grant a container access to docker so that it can spawn other containers on your host. You do this by exposing the docker socket inside the container, e.g: docker run -v /var/run/docker.
Containers can only communicate with each other if they share a network. Containers that don't share a network cannot communicate with one another. That's one of the isolation features provided by Docker. A container can belong to more than one network, and a network can have multiple containers inside.
Yes you can programmatically spawn a docker container. Docker Remote API will allow you to do that. You can either use http client library to invoke the remote APIs or you can use java docker client libraries to do the same.
Here is the relevant docker documentation:
Remote API:
https://docs.docker.com/engine/reference/api/docker_remote_api/
Libraries: https://docs.docker.com/engine/reference/api/remote_api_client_libraries/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With