简体   繁体   中英

Is it possible to launch a new Docker container from within a running Docker container using Docker Compose?

I have a Node.js application running inside a Docker Container.

I need to launch a new container from my Node.js application (via code; eg child_process.spawn() ) with the sole purpose of running a Python script. I also need to pass one argument (a database record ID) to this Python script. So the command is:

python main.py 56fb661b7e51f80736d48113

Note that I do not want this container to run inside the current container but rather to be a separate container.

I understand an orchestration framework such as Swarm or Kubernates would be better suited for this task, but it has been requested that I use Docker Compose locally on my machine in my development environment, and then we will use Kubernates in production.

Is it possible to launch a new Docker container (just a container, not a whole new machine/VM) from within a running Docker container using Docker Compose, and if so, how might I go about doing so?

I haven't done it myself, but from what I gather if your have docker installed on your child container, if you make the docker socket of the host available in the child you are able to interact with it. ie

--volume=/var/run/docker.sock:/tmp/docker.sock

You'll need to config your child's docker process to point to that socket (presumably the DOCKER_HOST envvar should work?) but thats the basic idea. Running docker commands against that socket should work on the host.

https://github.com/gliderlabs/registrator use this method which might help give you some pointers.

Obviously, this method of using docker creates a number of issues, but if its best for your situation then go for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM