From c6f6b835a7fbe149ccbad2bb6833e7a9dd17cc47 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 02:25:04 -0800 Subject: [PATCH 01/11] first test run of sharing with samba --- samba-share/Dockerfile | 15 ++++ samba-share/run.sh | 19 +++++ samba-share/samba-share.sh | 37 +++++++++ samba-share/setup-samba-share.sh | 125 +++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 samba-share/Dockerfile create mode 100755 samba-share/run.sh create mode 100755 samba-share/samba-share.sh create mode 100755 samba-share/setup-samba-share.sh diff --git a/samba-share/Dockerfile b/samba-share/Dockerfile new file mode 100644 index 0000000..36e6060 --- /dev/null +++ b/samba-share/Dockerfile @@ -0,0 +1,15 @@ +FROM debian:stable +LABEL CMDBUILD="docker build -t svendowideit/samba https://raw.githubusercontent.com/SvenDowideit/dockerfiles/master/samba/Dockerfile" +LABEL CMDRUN="socker run svendowideit/samba" + +MAINTAINER Sven Dowideit (@SvenDowideit) + +# gettext for envsubst +RUN apt-get update && \ + apt-get install -yq samba gettext +ADD share.tmpl /share.tmpl +ADD run.sh /run.sh +ADD setup-samba-share.sh /setup-samba-share.sh +ADD samba-share.sh /samba-share.sh + +ENTRYPOINT ["/run.sh"] diff --git a/samba-share/run.sh b/samba-share/run.sh new file mode 100755 index 0000000..3801820 --- /dev/null +++ b/samba-share/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# +# run.sh does one of these +# - execute samba +# - run sh commands to set up samba +# +set -e + +if [ "$1" == "--start" ] +then + shift 1 + /samba-share.sh "@?" +else + /setup-samba-share.sh "@?" +fi + + + + diff --git a/samba-share/samba-share.sh b/samba-share/samba-share.sh new file mode 100755 index 0000000..1bbacd6 --- /dev/null +++ b/samba-share/samba-share.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -e + +USER=${USER:-"root"} +PASSWORD=${PASSWORD:-"tcuser"} +USERID=${USERID:-1000} +GROUP=${GROUP:-"root"} + +args=("$@") +# Running as an Entrypoint means the script is not arg0 +echo "Setting up samba cfg ${args[@]}" + +LIMIT=${#args[@]} +# last one is an empty string +mv /etc/samba/smb.conf /etc/samba/smb.conf.bak +sed 's/\[global\]/\[global\]\n log level = 0/' /etc/samba/smb.conf.bak > /etc/samba/smb.conf +for ((i=2; i < LIMIT ; i++)); do + vol="${args[i]}" + echo "Adding volume \"$vol\"" + + export VOLUME=$vol + export VOLUME_NAME=$(echo "$VOLUME" |sed "s/\///" |tr '[\/<>:"\\|?*+;,=]' '_') + + cat /share.tmpl | envsubst >> /etc/samba/smb.conf +done + +#cat /etc/samba/smb.conf + +if ! id -u $USER > /dev/null 2>&1; then + useradd $USER --uid $USERID --user-group --password $PASSWORD --home-dir / +fi +/etc/init.d/samba start +echo "Watching /var/log/samba/*" +tail -f /var/log/samba/* +#this should allow the samba-server to be --rm'd +exit 0 + diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh new file mode 100755 index 0000000..b906c4f --- /dev/null +++ b/samba-share/setup-samba-share.sh @@ -0,0 +1,125 @@ +#!/bin/bash +set -e + +docker_host_execute() { + echo "$@" +} +output() { + docker_host_execute echo "$@" +} +error() { + output "ERROR: $@" +} + +usage() { + output + [ -n "$1" ] && error "$@" + output "Please run with:" + output " docker run svendowideit/samba-share \"$container\" | sh" + output "" + output " OR - depending on your Docker Host's location of its docker binary" + output "" + output " DOCKER=/usr/local/bin/docker /usr/local/bin/docker run svendowideit/samba-share \"$container\" | sh" + output "Maybe even add sudo." + output + docker_host_execute exit 1 + exit 1 +} + +docker_host_execute " +output() { + echo "$@" +} +docker_host_execute() { + true +}" + +# remove the default shell print +docker_host_execute PS1= + +# copy functions to sh +# http://stackoverflow.com/a/9895178 +docker_host_execute "`declare -f usage`" +docker_host_execute "`declare -f error`" + +# parse parameters +container=$1 + +# check parameters +if [ -z "$container" ] +then + error "No container name given. Replace with the name of the container to share volumes from." + container="" + usage +fi + +# create environment for sh +docker_host_execute "container=$container" +docker_host_execute "sambaContainer=`grep cpu[^a-zA-Z\d] /proc/1/cgroup | grep -oE '[0-9a-fA-F]{64}'`" +# It could be that parameters were passed as +# docker run -e USER=... svendowideit/samba-share \"$container\" | sh +# We set them like this so they must be named explicitely and +# are not accidentially taken from the environment. +docker_host_execute "USER=$USER" +docker_host_execute "PASSWORD=$PASSWORD" +docker_host_execute "USERID=$USERID" +docker_host_execute "GROUP=$GROUP" +docker_host_execute "READONLY=$READONLY" + +# define function for sh instead of a string for better syntax highlighting +execute_in_sh() + DOCKER=${DOCKER:-"docker"} + + if ! type $DOCKER 2>>/dev/null + then + usage "Could run docker command as \"$DOCKER\". Please specify where to find the docker binary." + fi + + # check if variable transfer from host to shell worked + if [ -z "$container" ] || [ -z "$sambaContainer" ] + then + error "Could not transfer necessary variables form docker container. Not your fault." + exit 1 + fi + + if ! $DOCKER inspect "$container" 1>>/dev/null 2>>/dev/null + then + usage "Container \"$container\" does not exist." + fi + + volumes=`$DOCKER inspect --format="{{range \$k,\$v := .Config.Volumes}}{{println \$k}}{{end}}" $container | grep -v -E "^$" + $DOCKER inspect --format="{{range \$k,\$v := .Volumes }}{{println \$k}}{{end}}" $container | grep -v -E "^$"` + + if [ -z "$volumes" ] + then + usage "Could not detect any volumes to share in container \"$container\"." + fi + + if $DOCKER inspect --format "{{.State.Running}}" samba-server >/dev/null 2>&1 + then + output "Stopping and removing existing server." + $DOCKER stop samba-server > /dev/null 2>&1 + $DOCKER rm samba-server >/dev/null 2>&1 + fi + + echo "Starting \"samba-server\" container sharing the volumes ${volumes[@]} of container \"${container}\"." + + # from here we should pass the work off to the real samba container + # I'm running this in the background rather than using run -d, so that --rm will still work + $docker run --rm --name samba-server \ + --expose 137 -p 137:137 \ + --expose 138 -p 138:138 \ + --expose 139 -p 139:139 \ + --expose 445 -p 445:445 \ + -e USER -e PASSWORD -e USERID -e GROUP -e READONLY \ + --volumes-from ${container} \ + ${sambaImage} --start ${container} ${volumes[@]} > /dev/null 2>&1& + +} + +# copy execute_in_sh to sh +docker_host_execute "`declare -f execute_in_sh`" + +# execute execute_in_sh in sh +docker_host_execute execute_in_sh + From dcd92813384516372d9d99ebb92966b9902096b9 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 03:31:52 -0800 Subject: [PATCH 02/11] added hints on how to go on --- samba-share/README.md | 0 samba-share/run.sh | 4 +- samba-share/setup-samba-share.sh | 102 ++++++++++++++++++++++++------- samba-share/share.tmpl | 11 ++++ 4 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 samba-share/README.md create mode 100644 samba-share/share.tmpl diff --git a/samba-share/README.md b/samba-share/README.md new file mode 100644 index 0000000..e69de29 diff --git a/samba-share/run.sh b/samba-share/run.sh index 3801820..03dd702 100755 --- a/samba-share/run.sh +++ b/samba-share/run.sh @@ -9,9 +9,9 @@ set -e if [ "$1" == "--start" ] then shift 1 - /samba-share.sh "@?" + /samba-share.sh "$@" else - /setup-samba-share.sh "@?" + /setup-samba-share.sh "$@" fi diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index b906c4f..fe5d168 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -11,9 +11,7 @@ error() { output "ERROR: $@" } -usage() { - output - [ -n "$1" ] && error "$@" +print_usage() { output "Please run with:" output " docker run svendowideit/samba-share \"$container\" | sh" output "" @@ -21,11 +19,21 @@ usage() { output "" output " DOCKER=/usr/local/bin/docker /usr/local/bin/docker run svendowideit/samba-share \"$container\" | sh" output "Maybe even add sudo." +} + +usage() { + output + [ -n "$1" ] && error "$@" + print_usage output docker_host_execute exit 1 exit 1 } + +# remove the default shell print +docker_host_execute PS1= + docker_host_execute " output() { echo "$@" @@ -34,13 +42,12 @@ docker_host_execute() { true }" -# remove the default shell print -docker_host_execute PS1= # copy functions to sh # http://stackoverflow.com/a/9895178 -docker_host_execute "`declare -f usage`" -docker_host_execute "`declare -f error`" +declare -f usage +declare -f print_usage +declare -f error # parse parameters container=$1 @@ -67,14 +74,18 @@ docker_host_execute "GROUP=$GROUP" docker_host_execute "READONLY=$READONLY" # define function for sh instead of a string for better syntax highlighting -execute_in_sh() - DOCKER=${DOCKER:-"docker"} - - if ! type $DOCKER 2>>/dev/null +execute_in_sh() { + + if [ -z "$DOCKER" ] + then + DOCKER=docker + fi + + if ! type "$DOCKER" 2>>/dev/null 1>>/dev/null then usage "Could run docker command as \"$DOCKER\". Please specify where to find the docker binary." fi - + # check if variable transfer from host to shell worked if [ -z "$container" ] || [ -z "$sambaContainer" ] then @@ -87,8 +98,8 @@ execute_in_sh() usage "Container \"$container\" does not exist." fi - volumes=`$DOCKER inspect --format="{{range \$k,\$v := .Config.Volumes}}{{println \$k}}{{end}}" $container | grep -v -E "^$" - $DOCKER inspect --format="{{range \$k,\$v := .Volumes }}{{println \$k}}{{end}}" $container | grep -v -E "^$"` + volumes=`$DOCKER inspect --format='{{range \$k,\$v := .Config.Volumes}}{{println \$k}}{{end}}' "$container" | grep -v -E "^$" + $DOCKER inspect --format='{{range \$k,\$v := .Volumes}}{{println \$k}}{{end}}' "$container" | grep -v -E "^$"` if [ -z "$volumes" ] then @@ -97,29 +108,76 @@ execute_in_sh() if $DOCKER inspect --format "{{.State.Running}}" samba-server >/dev/null 2>&1 then - output "Stopping and removing existing server." + echo "Stopping and removing existing server." $DOCKER stop samba-server > /dev/null 2>&1 $DOCKER rm samba-server >/dev/null 2>&1 fi - echo "Starting \"samba-server\" container sharing the volumes ${volumes[@]} of container \"${container}\"." + sambaImage=`$DOCKER inspect --format='{{.Config.Image}}' "$sambaContainer"` + if [ -z "$sambaImage" ] + then + error "Could not find samba image of container \"$sambaContainer\"." + exit 1 + fi + + server_container_name=samba-server + echo "Starting \"$server_container_name\" container sharing the volumes" $volumes "of container \"${container}\"." # from here we should pass the work off to the real samba container # I'm running this in the background rather than using run -d, so that --rm will still work - $docker run --rm --name samba-server \ + $DOCKER run --rm --name "$server_container_name" \ --expose 137 -p 137:137 \ --expose 138 -p 138:138 \ --expose 139 -p 139:139 \ --expose 445 -p 445:445 \ - -e USER -e PASSWORD -e USERID -e GROUP -e READONLY \ - --volumes-from ${container} \ - ${sambaImage} --start ${container} ${volumes[@]} > /dev/null 2>&1& - + -e USER -e PASSWORD -e USERID -e GROUP \ + --volumes-from "$container" \ + "$sambaImage" --start "$container" $volumes > /dev/null 2>&1& + + # wait for the container to finish and remove it + $DOCKER wait "$sambaContainer" 2>>/dev/null 1>>/dev/null + $DOCKER rm "$sambaContainer" 2>>/dev/null 1>>/dev/null + + # give advice + # http://stackoverflow.com/a/20686101 + ips="`docker inspect --format ' {{ .NetworkSettings.IPAddress }}' "$server_container_name"`" + example_ip="`echo "$ips" | head -n1`" + echo "" + echo "# run 'docker logs samba-server' to view the samba logs" + echo "" + echo "================================================" + echo "" + echo "Your data volume (" $volumes ") should now be accessible at \\\\$example_ip\ as 'guest' user (no password)" + echo "" + echo "For example, on OSX, using a typical boot2docker vm:" + echo " goto Go|Connect to Server in Finder" + echo " enter 'cifs://$example_ip" + echo " hit the 'Connect' button" + echo " select the volumes you want to mount" + echo " choose the 'Guest' radiobox and connect" + echo + echo "Or on Linux:" + echo " mount -t cifs //$example_ip/data /mnt/data -o username=guest" + echo + echo "Or on Windows:" + echo " Enter '\\\\$example_ip\\data' into Explorer" + echo " Log in as Guest - no password" + echo "" + echo "Ip addresses: " + echo "$ips" + echo "" + exit 0 } # copy execute_in_sh to sh -docker_host_execute "`declare -f execute_in_sh`" +declare -f execute_in_sh # execute execute_in_sh in sh docker_host_execute execute_in_sh +# finally, if you did not pipe it to sh, you may need some output +output() { + echo "# $@" +} +print_usage + diff --git a/samba-share/share.tmpl b/samba-share/share.tmpl new file mode 100644 index 0000000..60a7161 --- /dev/null +++ b/samba-share/share.tmpl @@ -0,0 +1,11 @@ +[${VOLUME_NAME}] + comment = ${VOLUME_NAME} volume from ${CONTAINER} + read only = ${READONLY} + locking = no + path = ${VOLUME} + force user = ${USER} + force group = ${GROUP} + guest ok = yes + map archive = no + map system = no + map hidden = no From 07fe4162f713839e0f8a7c2e7b0f85c2dc9a65fb Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 03:37:14 -0800 Subject: [PATCH 03/11] removed escaping bugs --- samba-share/setup-samba-share.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index fe5d168..b823e41 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -106,13 +106,6 @@ execute_in_sh() { usage "Could not detect any volumes to share in container \"$container\"." fi - if $DOCKER inspect --format "{{.State.Running}}" samba-server >/dev/null 2>&1 - then - echo "Stopping and removing existing server." - $DOCKER stop samba-server > /dev/null 2>&1 - $DOCKER rm samba-server >/dev/null 2>&1 - fi - sambaImage=`$DOCKER inspect --format='{{.Config.Image}}' "$sambaContainer"` if [ -z "$sambaImage" ] then @@ -121,6 +114,14 @@ execute_in_sh() { fi server_container_name=samba-server + + if $DOCKER inspect --format "{{.State.Running}}" "$server_container_name" >/dev/null 2>&1 + then + echo "Stopping and removing existing server." + $DOCKER stop "$server_container_name" > /dev/null 2>&1 + $DOCKER rm "$server_container_name" >/dev/null 2>&1 + fi + echo "Starting \"$server_container_name\" container sharing the volumes" $volumes "of container \"${container}\"." # from here we should pass the work off to the real samba container @@ -141,13 +142,13 @@ execute_in_sh() { # give advice # http://stackoverflow.com/a/20686101 ips="`docker inspect --format ' {{ .NetworkSettings.IPAddress }}' "$server_container_name"`" - example_ip="`echo "$ips" | head -n1`" + example_ip="`echo "$ips" | head -n1 | grep -o -E '\S+'`" echo "" - echo "# run 'docker logs samba-server' to view the samba logs" + echo "# run 'docker logs \"$server_container_name\"' to view the samba logs" echo "" echo "================================================" echo "" - echo "Your data volume (" $volumes ") should now be accessible at \\\\$example_ip\ as 'guest' user (no password)" + echo "Your data volume (" $volumes ") should now be accessible at "'\\'"$example_ip"'\'" as 'guest' user (no password)" echo "" echo "For example, on OSX, using a typical boot2docker vm:" echo " goto Go|Connect to Server in Finder" @@ -160,7 +161,7 @@ execute_in_sh() { echo " mount -t cifs //$example_ip/data /mnt/data -o username=guest" echo echo "Or on Windows:" - echo " Enter '\\\\$example_ip\\data' into Explorer" + echo " Enter "'\\'"$example_ip"'\'"data' into Explorer" echo " Log in as Guest - no password" echo "" echo "Ip addresses: " From 1bed7e95c2750d87b90bb22ed886af58bfc5b4e4 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:11:54 -0800 Subject: [PATCH 04/11] made samba server run and share a volumt --- samba-share/Dockerfile | 3 +-- samba-share/samba-share.sh | 45 ++++++++++++++++++++------------ samba-share/setup-samba-share.sh | 8 +++--- samba-share/share.tmpl | 11 -------- 4 files changed, 33 insertions(+), 34 deletions(-) delete mode 100644 samba-share/share.tmpl diff --git a/samba-share/Dockerfile b/samba-share/Dockerfile index 36e6060..93c35ac 100644 --- a/samba-share/Dockerfile +++ b/samba-share/Dockerfile @@ -1,13 +1,12 @@ FROM debian:stable LABEL CMDBUILD="docker build -t svendowideit/samba https://raw.githubusercontent.com/SvenDowideit/dockerfiles/master/samba/Dockerfile" -LABEL CMDRUN="socker run svendowideit/samba" +LABEL CMDRUN="docker run svendowideit/samba" MAINTAINER Sven Dowideit (@SvenDowideit) # gettext for envsubst RUN apt-get update && \ apt-get install -yq samba gettext -ADD share.tmpl /share.tmpl ADD run.sh /run.sh ADD setup-samba-share.sh /setup-samba-share.sh ADD samba-share.sh /samba-share.sh diff --git a/samba-share/samba-share.sh b/samba-share/samba-share.sh index 1bbacd6..655e888 100755 --- a/samba-share/samba-share.sh +++ b/samba-share/samba-share.sh @@ -1,37 +1,48 @@ #!/bin/bash -set -e +#set -e USER=${USER:-"root"} PASSWORD=${PASSWORD:-"tcuser"} USERID=${USERID:-1000} GROUP=${GROUP:-"root"} +READONLY=${READONLY:-"no"} -args=("$@") -# Running as an Entrypoint means the script is not arg0 -echo "Setting up samba cfg ${args[@]}" +CONTAINER="$1" +shift 1 -LIMIT=${#args[@]} -# last one is an empty string -mv /etc/samba/smb.conf /etc/samba/smb.conf.bak -sed 's/\[global\]/\[global\]\n log level = 0/' /etc/samba/smb.conf.bak > /etc/samba/smb.conf -for ((i=2; i < LIMIT ; i++)); do - vol="${args[i]}" - echo "Adding volume \"$vol\"" +echo "Setting loglevel to 0." +sed 's/\[global\]/\[global\]\n log level = 0/' -i.bak /etc/samba/smb.conf - export VOLUME=$vol - export VOLUME_NAME=$(echo "$VOLUME" |sed "s/\///" |tr '[\/<>:"\\|?*+;,=]' '_') +echo "Setting up samba configuration for container \"$CONTAINER\" and volumes "$@"." - cat /share.tmpl | envsubst >> /etc/samba/smb.conf +for VOLUME in "$@" +do + echo "Adding volume \"$VOLUME\"." + + VOLUME_NAME=`echo "$VOLUME" | sed "s/\///" | tr '[\/<>:"\\|?*+;,=]' '_'` + + echo "[$VOLUME_NAME] + comment = ${VOLUME_NAME} volume from ${CONTAINER} + read only = ${READONLY} + locking = no + path = ${VOLUME} + force user = ${USER} + force group = ${GROUP} + guest ok = yes + map archive = no + map system = no + map hidden = no" >> /etc/samba/smb.conf done -#cat /etc/samba/smb.conf +cat /etc/samba/smb.conf -if ! id -u $USER > /dev/null 2>&1; then +if ! id -u $USER > /dev/null 2>&1 +then useradd $USER --uid $USERID --user-group --password $PASSWORD --home-dir / fi /etc/init.d/samba start echo "Watching /var/log/samba/*" tail -f /var/log/samba/* -#this should allow the samba-server to be --rm'd +# This should allow the samba-server to be removed by --rm. exit 0 diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index b823e41..3188f96 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -126,12 +126,12 @@ execute_in_sh() { # from here we should pass the work off to the real samba container # I'm running this in the background rather than using run -d, so that --rm will still work - $DOCKER run --rm --name "$server_container_name" \ + $DOCKER run --rm --name "$server_container_name" \ --expose 137 -p 137:137 \ --expose 138 -p 138:138 \ --expose 139 -p 139:139 \ --expose 445 -p 445:445 \ - -e USER -e PASSWORD -e USERID -e GROUP \ + -e USER -e PASSWORD -e USERID -e GROUP -e READONLY \ --volumes-from "$container" \ "$sambaImage" --start "$container" $volumes > /dev/null 2>&1& @@ -148,7 +148,7 @@ execute_in_sh() { echo "" echo "================================================" echo "" - echo "Your data volume (" $volumes ") should now be accessible at "'\\'"$example_ip"'\'" as 'guest' user (no password)" + echo "Your data volumes (" $volumes ") should now be accessible at "'\''\'"$example_ip"'\'" as 'guest' user (no password)" echo "" echo "For example, on OSX, using a typical boot2docker vm:" echo " goto Go|Connect to Server in Finder" @@ -161,7 +161,7 @@ execute_in_sh() { echo " mount -t cifs //$example_ip/data /mnt/data -o username=guest" echo echo "Or on Windows:" - echo " Enter "'\\'"$example_ip"'\'"data' into Explorer" + echo " Enter "'\''\'"$example_ip"'\'"data' into Explorer" echo " Log in as Guest - no password" echo "" echo "Ip addresses: " diff --git a/samba-share/share.tmpl b/samba-share/share.tmpl deleted file mode 100644 index 60a7161..0000000 --- a/samba-share/share.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -[${VOLUME_NAME}] - comment = ${VOLUME_NAME} volume from ${CONTAINER} - read only = ${READONLY} - locking = no - path = ${VOLUME} - force user = ${USER} - force group = ${GROUP} - guest ok = yes - map archive = no - map system = no - map hidden = no From ab44739d1a2e6d572637797dbb00b9559c45c20e Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:31:03 -0800 Subject: [PATCH 05/11] added README --- samba-share/README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/samba-share/README.md b/samba-share/README.md index e69de29..927ccde 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -0,0 +1,38 @@ + + +# Samba Docker volume sharing plugin + +Sharing a Docker container's volume should be as simple as `docker run niccokunzmann/samba-share | sh`. + +This 'plugin' will create and configure a samba server container that auto-creates shares for all +the volumes attached to the specified container. + +## Usage + + +Possible scenarios are + +- `docker run niccokunzmann/samba-share | sh` shares the volumes of ``. +- `docker run niccokunzmann/samba-share` reminds the user what the options are. +- Additional parameters can be [passed as environment variable](https://docs.docker.com/engine/reference/run/#env-environment-variables) and can be combined. Possible names are USER PASSWORD USERID GROUP READONLY. Example: + + docker run -e READONLY=yes niccokunzmann/samba-share | sh + +## Try it out + +Create a volume in my-data and share its content via samba + + # Make a volume container (only need to do this once) + docker run -v /data --name my-data busybox true + # Share it using Samba (Windows file sharing) + docker run niccokunzmann/samba-share my-data | sh + +## How it works + +The `niccokunzmann/samba-share` container uses the bind-mounted docker client and socket to introspect +the configuration of the specified container, and then uses that information to setup a new container +that is `--volumes-from` setup to give it access. + +## Credits + +This was derived from `niccokunzmann/samba` by [Nicco Kunzmann](https://github.com/niccokunzmann/) From d7ebeaf4843571efc894d4b885310ac1af635e55 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:40:14 -0800 Subject: [PATCH 06/11] made niccokunzmann maintainer --- samba-share/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samba-share/Dockerfile b/samba-share/Dockerfile index 93c35ac..2715448 100644 --- a/samba-share/Dockerfile +++ b/samba-share/Dockerfile @@ -1,8 +1,9 @@ FROM debian:stable -LABEL CMDBUILD="docker build -t svendowideit/samba https://raw.githubusercontent.com/SvenDowideit/dockerfiles/master/samba/Dockerfile" -LABEL CMDRUN="docker run svendowideit/samba" +LABEL CMDBUILD="docker build -t niccokunzmann/samba-share https://raw.githubusercontent.com/niccokunzmann/dockerfiles/master/samba-share/Dockerfile" +LABEL CMDRUN="docker run niccokunzmann/samba-share" MAINTAINER Sven Dowideit (@SvenDowideit) +MAINTAINER Nicco Kunzmann (@dannhaltohneson) # gettext for envsubst RUN apt-get update && \ From 4ac885a265bed7e6a0e410edf6cb1b40e5e73b30 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:40:34 -0800 Subject: [PATCH 07/11] added history of why this was created --- samba-share/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samba-share/README.md b/samba-share/README.md index 927ccde..9881ec7 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -35,4 +35,4 @@ that is `--volumes-from` setup to give it access. ## Credits -This was derived from `niccokunzmann/samba` by [Nicco Kunzmann](https://github.com/niccokunzmann/) +This was derived from [`svendowideit/samba`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba) to [niccokunzmann/samba-share](https://github.com/SvenDowideit/dockerfiles/tree/master/samba-share) because of [Issue 29](https://github.com/SvenDowideit/dockerfiles/issues/29). From f2722bbca9f70b3e7a930139ae0bdbfdbf3950f9 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:41:31 -0800 Subject: [PATCH 08/11] made reference to samba-share --- samba-share/setup-samba-share.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index 3188f96..71f36fa 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -13,11 +13,11 @@ error() { print_usage() { output "Please run with:" - output " docker run svendowideit/samba-share \"$container\" | sh" + output " docker run niccokunzmann/samba-share \"$container\" | sh" output "" output " OR - depending on your Docker Host's location of its docker binary" output "" - output " DOCKER=/usr/local/bin/docker /usr/local/bin/docker run svendowideit/samba-share \"$container\" | sh" + output " DOCKER=/usr/local/bin/docker /usr/local/bin/docker run niccokunzmann/samba-share \"$container\" | /bin/sh" output "Maybe even add sudo." } @@ -55,16 +55,19 @@ container=$1 # check parameters if [ -z "$container" ] then - error "No container name given. Replace with the name of the container to share volumes from." + # some spacing in case this is not piped to sh + docker_host_execute + docker_host_execute + docker_host_execute # Hello user! Read the message below: container="" - usage + usage "No container name given. Replace with the name of the container to share volumes from." fi # create environment for sh docker_host_execute "container=$container" docker_host_execute "sambaContainer=`grep cpu[^a-zA-Z\d] /proc/1/cgroup | grep -oE '[0-9a-fA-F]{64}'`" # It could be that parameters were passed as -# docker run -e USER=... svendowideit/samba-share \"$container\" | sh +# docker run -e USER=... niccokunzmann/samba-share \"$container\" | sh # We set them like this so they must be named explicitely and # are not accidentially taken from the environment. docker_host_execute "USER=$USER" From fb7c3cb9e94df20a30a267f2c73066ecf826ea15 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:44:39 -0800 Subject: [PATCH 09/11] fixed typo --- samba-share/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samba-share/README.md b/samba-share/README.md index 9881ec7..ae99a73 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -35,4 +35,4 @@ that is `--volumes-from` setup to give it access. ## Credits -This was derived from [`svendowideit/samba`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba) to [niccokunzmann/samba-share](https://github.com/SvenDowideit/dockerfiles/tree/master/samba-share) because of [Issue 29](https://github.com/SvenDowideit/dockerfiles/issues/29). +This was derived from [`svendowideit/samba`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba) to [`niccokunzmann/samba-share`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba-share) because of [Issue 29](https://github.com/SvenDowideit/dockerfiles/issues/29). From b35789dd01ebe5bfbdb43f7afd7cd3990a92d165 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:53:18 -0800 Subject: [PATCH 10/11] updated link --- samba-share/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samba-share/README.md b/samba-share/README.md index ae99a73..84a0bc4 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -9,7 +9,6 @@ the volumes attached to the specified container. ## Usage - Possible scenarios are - `docker run niccokunzmann/samba-share | sh` shares the volumes of ``. @@ -35,4 +34,4 @@ that is `--volumes-from` setup to give it access. ## Credits -This was derived from [`svendowideit/samba`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba) to [`niccokunzmann/samba-share`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba-share) because of [Issue 29](https://github.com/SvenDowideit/dockerfiles/issues/29). +This was derived from [`svendowideit/samba`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba) to [`niccokunzmann/samba-share`](https://github.com/niccokunzmann/dockerfiles/tree/master/samba-share) because of [Issue 29](https://github.com/SvenDowideit/dockerfiles/issues/29). From 8ea3094259e2e6b028dbf8b3fe388675bc486b4a Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 13:52:13 +0100 Subject: [PATCH 11/11] added tested section --- samba-share/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/samba-share/README.md b/samba-share/README.md index 84a0bc4..d2589ab 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -32,6 +32,25 @@ The `niccokunzmann/samba-share` container uses the bind-mounted docker client an the configuration of the specified container, and then uses that information to setup a new container that is `--volumes-from` setup to give it access. +## Tested + +- + Client: + Version: 1.9.1 + API version: 1.21 + Go version: go1.4.2 + Git commit: a34a1d5 + Built: Fri Nov 20 13:20:08 UTC 2015 + OS/Arch: linux/amd64 + + Server: + Version: 1.9.1 + API version: 1.21 + Go version: go1.4.2 + Git commit: a34a1d5 + Built: Fri Nov 20 13:20:08 UTC 2015 + OS/Arch: linux/amd64 + ## Credits This was derived from [`svendowideit/samba`](https://github.com/SvenDowideit/dockerfiles/tree/master/samba) to [`niccokunzmann/samba-share`](https://github.com/niccokunzmann/dockerfiles/tree/master/samba-share) because of [Issue 29](https://github.com/SvenDowideit/dockerfiles/issues/29).