Docker Community Forums

Share and learn in the Docker community.

execute command from a container to another container?


(Acayipsin) #1

Hi guys,

I have a small question about docker property and hope you can help me.

My question is:

  • Is it possible to execute command from a container to another container?

Example:

It runs two containers with the following names:

  • container_one (based on centos)
  • container_two (based on centos)

I now producing the two containers from the Image centos and let it run in the background:

  • docker run -itd --name container_one centos /bin/bash
  • docker run -itd --name container_two centos /bin/bash

Now I log me in “container_one”

  • docker exec -it container_one /bin/bash

Now I am in the terminal of “container_one” and wants from this terminal, for example, a file create in “container_two”. Is there a way, the command “touch test” of “container_one” made in “container_two” run, so that the file in “container_two” generated.


(Zhang Xiangjun) #2

What you want may be a volume shared by the two containers.