Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach stdout of one docker container to stdin of another docker container

I would like to pipe the stdout of a script in container A to stdin of container B and then pipe stdout of container B to stdin of container C. I would like to know what is the best practice to do the same.

Option 1

docker run -it ImageA python script1.py | docker run -it ImageB python script2.py |  \ 
docker run -it Image3 python script3.py

Option 2

Use a shared volume to store data that can be accessed by subsequent containers.

docker run -it -v /home/shared_volume:/container1_home/shared_volume python script1.py 

docker run -it -v /home/shared_volume:/container2_home/shared_volume python script2.py 

docker run -it -v /home/shared_volume:/container3_home/shared_volume python script3.py 

Ideally, I prefer to not use shared volumes. The output of script1.py and script2.py produce intermediate files (or streams of data) that are in the order of several terabytes. I am not interested in these files, I would prefer to store only the results of script3.py to disk.

like image 883
Vishnu Avatar asked Feb 02 '26 02:02

Vishnu


1 Answers

Can you try the same by running it without -t option; I was able to do sample one like below and it is working

$docker run -i ubuntu:xenial ls -l | docker run -i ubuntu:xenial wc -l
$20
like image 133
Viswesn Avatar answered Feb 04 '26 00:02

Viswesn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!