Can I call command's container B inside my container A?

I’m configuring two docker containers, container A and container B. Is it possible to call a command of B inside A, using any configuration like network or link or some other?

I tried with network and link but I didn’t have success.

This configuration I would like to do for separate a container that will use a lot of CPU from the other.

I expected call a B container inside container A in a transparently way, and up other new "B"s containers when necessary.

Hi @julianopache. I’m trying to make sure I understand your question correctly before giving an answer…

Is what you’re asking is whether you can start another container (B) from within container A? Or are you wanting to run a command in container B with a process running in Container A?

I don’t believe this is possible if it’s the second question, as the point of containers is to isolate the process space from other containers. Each can only run processes in their own container. Having said that, if the process in Container B listens on the network for commands for it to run, assuming that the binary for the process is included in the build of the image for Container B, you might be able to send such a message to Container B from Container A that will cause Container B to run the requested process.

If you’re rather wanting to start another Container (B) from with Container A, this is essentially Docker in Docker. The way to arrange that is to have the Docker daemon on the host listen on a TCP port instead or in addition to the normal file-based socket. Container A then must also include the docker command in its image. Also, in order for Container A to know what ip address and port to which it should connect, those should be passed to Container A as environment variables on startup. To be clear, these are the Docker Host’s ip address and TCP port on which it is listening for Docker API calls. Container A will make calls like docker -H <ip address>:<port> ... and the docker daemon on the host machine will create the container as requested, assuming everything is setup correctly. A point of concern though is that if someone were to compromise Container A and gain access to it, they could run arbitrary containers from your container. For that reason, it would be best if Container A had no external network access which might be compromised.

Not sure if I answered your question or not. If not, please post an update with more details about exactly what you’re trying to accomplish.

Thanks for your answer @dannc .

My question is more related from your second sugestion, and now I think I understand more about what you wrote.

Just in case, let me explain a little more using the example below:

In container B I have Tesseract OCR software installed, and I can use it by the prompt through the following command:

tesseract imagename outputbase

What I would like to do is call this command inside container A to delegate the CPU cost to container B. So, I tried somethings like link and network docker configurations, but it´s not working.
Now with you asnwer, it became clear to me that I couldn’t call process commands from one container to another. It is?