2

Imagine a hypothetical shell that launches all commands in ad-hoc containers with some isolation and resource controls depending on function of each command:

cat foo.txt | sed ... | xargs some-command

An example would be that each command has some limits on memory, no network or read-only mounted filesystem(s).

Is such shell possible to implement in a transparent way so that processes would be unaware that each runs in a container and can use UNIX pipes, send signals etc.?

0

1 Answer 1

2

If I understand what you're asking, I don't see why this wouldn't be possible, so long as the containers at the various boundaries of the pipes properly took STDIN in and emitting everything out via STDOUT.

You're basically asking this:

$ cat.txt | <container 1 app> | <container 2 app> | ...

This should work.

Example

Here I have a docker container that does nothing more than run this script:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
28c19c338e6e        sleeper             "/tmp/run.sh"       6 days ago          Up 4 minutes                            focused_lumiere

And the script inside:

$ docker exec -it 28c19c338e6e cat /tmp/run.sh
#!/bin/bash

while true; do sleep 30; done

Now if we were to run commands like this:

$ docker exec -it 28c19c338e6e bash -c "echo hi" | \
  docker exec -i  28c19c338e6e bash -c "grep hi"
hi
$

And if we were to grep for something else:

$ docker exec -it 28c19c338e6e bash -c "echo hi" | \
  docker exec -i  28c19c338e6e bash -c "grep bye"
$

Each of these docker commands is running their respective command inside the container, but they're passing input/output via STDIN/STDOUT with the Bash shell and pipes that I'm running them on.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .