Monday, September 30, 2019

Named pipes & docker

Named pipes can be used to send commands from docker container to host

Host
---------
#!/bin/bash

pipe=/tmp/testpipe.pipe

trap "rm -f $pipe" EXIT

if [[ ! -p $pipe ]]; then
    mkfifo $pipe
fi

while true
do
    if read line <$pipe; then
        if [[ "$line" == 'quit' ]]; then
            break
        fi
        echo $line
    fi
done

Docker
---------

sudo docker run --rm --name namedp -v /tmp/pipe1:/tmp/pipe1:rw -it debian:stable-slim bash

once in docker...

$ echo "Hi World!" >/tmp/pipe1

No comments:

Post a Comment