-2

Does exist any way to do this:

  • run one service (container) with main application - server (flask application);
  • server allows to run another services, them are also flask applications;
  • but I want to run each new service in separate container ?

For example, I have endpoint /services/{id}/run at the server, each id is some service id. Docker image is the same for all services, each service is running on separate port.

I would like something like this:

request to server - <host>//services/<id>/run -> application at server make some magic command/send message to somewhere -> service with id starts in new container.


I know that at least locally I can use docker-in-docker or simply mount docker socket in container and work with docker inside this container. But I would like to find way to work across multiple machines (each service can run on another machine).

For Kubernetes: I know how create and run pods and deployments, but I can't find how to run new container on command from another container. Can I somehow communicate with k8s from container to run new container?


Generally:

  • can I run new container from another without docker-in-docker and mounting docker socket;

  • can I do it with/without Kubernetes?.


Thanks for advance.

Alex Kolosov
  • 15
  • 1
  • 5
  • This isn't a best practice. In Kubernetes it's a little less risky than in plain Docker (look up how to call the Kubernetes API) but it's complicated to manage and easily opens you up to denial-of-service attacks. Better is to use a job queue like RabbitMQ and a worker that can be managed by a Deployment object. – David Maze Dec 03 '19 at 14:32
  • I understand that it isn't the best practice. So I would like to know what is. How can I initiate running of new docker container from another container? My question not only about Kubernetes, but can I solve this problem using any tool(s). – Alex Kolosov Dec 03 '19 at 15:03
  • As previous community member said. This is not a best practice. I would suggest looking at this links: 1.[StackOverflow control docker from container](https://stackoverflow.com/questions/39468841/is-it-possible-to-start-a-stopped-container-from-another-container/39469893#394698930 2. [Exposing dockerd api](https://success.docker.com/article/how-do-i-enable-the-remote-api-for-dockerd) 3.[Docker engine security](https://docs.docker.com/engine/security/https/). Is there any particular reason that you need to start containers this way? – Dawid Kruk Dec 04 '19 at 12:01
  • @DawidKruk Thank you for links. Particular example: machine learning deployment. Services: frontend, backend. Frontend = UI where I can select model from list and click button "Deploy" (calls some backend endpoint). Then backend runs new model server in separate container. – Alex Kolosov Dec 04 '19 at 14:52
  • @AlexKolosov are these deployments which will calculate something will be created by you? Most important do you intend to give access to other people to run it? – Dawid Kruk Dec 09 '19 at 13:58
  • @DawidKruk Both in production and dev the goal - collaborative work: anyone, who has access, can press button "Deploy" on UI at server (or call endpoint). As result - new container with model will run. In dev I would like to do without k8s. But the principle is the same: do some command inside one container -> run new container. I would like just to know all ways to run new docker container from another, with and without k8s. Except using docker-in-docker and docker-out-of-docker. If they are exist, of course - I couldn't find:( If no - than no, I want just to know. Thanks. – Alex Kolosov Dec 11 '19 at 14:55
  • I would encourage you to look at this 2 links: 1.[Kubernetes access API](https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/) 2.[Kubeflow](https://www.kubeflow.org/) – Dawid Kruk Dec 19 '19 at 11:44
  • @DawidKruk Thank you for your answers! I worked with Kubeflow, now I'll dig around in Kubernetes API/ – Alex Kolosov Dec 20 '19 at 07:10
  • @AlexKolosov I answered your question with all the links that we talked about. If this helped you please upvote/accept it. – Dawid Kruk Dec 20 '19 at 10:12

1 Answers1

0

I've compiled all of the links that were in the comments under the question. I would advise taking a look into them:

Docker:

Kubernetes:

Dawid Kruk
  • 8,982
  • 2
  • 22
  • 45