DEV Community

Discussion on: What are your UNIX pipeline commands that saved you from lot of coding/time?

Collapse
 
dvdmuckle profile image
David Muckle • Edited

xargs is amazing for just about anything that doesn't like piped results. Want to pull a bunch of Docker images in one command?

echo "ubuntu gcc alpine nginx" | xargs -n 1 docker pull
Collapse
 
bertvv profile image
Bert Van Vreckem

So if I understand correctly, this is equivalent to the following?

for img in ubuntu gcc alpine nginx; do docker pull "${img}"; done

I never thought of using xargs this way, good to know!

I guess you could parallellize the loop by adding -P 0 to the xargs invocation.

Collapse
 
dvdmuckle profile image
David Muckle • Edited

I didn't consider using parallelization, that's a great idea! Though, what happens with Docker if it pulls in two copies of the same image at once? If two images have the same dependency, will Docker deal with this parallel pull fine, or will it bork?

EDIT: Docker seems to handle this rather well; It just queues up the layer pulls in some arbitrary order. Still, I don't know if I entirely trust this, but I can't see a reason for this to not work (And I can see a reason that one might want this to work!).

Collapse
 
djviolin profile image
István Lantos

This is cool! I never thought about that.