Last active
May 20, 2016 19:56
-
-
Save toonetown/cbb006b81e3e54eccbec301af9dbf7bf to your computer and use it in GitHub Desktop.
Allows passing of data from the host to a docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# A script to facilitate passing data from host to container in a daemon | |
# | |
# To read a variable (from within the container): | |
# VAR="$(docker_pipe read)" | |
# | |
# !!! Note that reading a variable will block until it is written to !!! | |
# | |
# To write to the variable that is being read (from the host): | |
# echo "Value" | docker exec -i <CONTAINER_ID> docker_pipe write | |
: ${FIFO_NAME:=/tmp/docker_pipe} | |
function cleanup { rm -f "${FIFO_NAME}"; exit ${1}; } | |
case "${1}" in | |
"read") | |
trap cleanup SIGHUP SIGINT SIGTERM EXIT | |
mkfifo "${FIFO_NAME}" || exit $? | |
cat "${FIFO_NAME}" || exit $? | |
;; | |
"write") | |
[ -p "${FIFO_NAME}" ] || { echo "${FIFO_NAME} does not exist."; exit 1; } | |
cat /dev/stdin > "${FIFO_NAME}" | |
;; | |
*) | |
echo "Usage: ${0} <read|write>" >&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment