Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start docker container from another application in another docker container

Tags:

docker

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?

like image 602
CHRISTIANJ Avatar asked Jun 02 '16 02:06

CHRISTIANJ


People also ask

Can a docker container start another 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.

Can two Docker containers talk to each other?

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.


1 Answers

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/

like image 173
Shibashis Avatar answered Oct 11 '22 08:10

Shibashis