From 82bb840876db00221711a18efcee5e191b3c8200 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Sun, 13 Dec 2015 17:05:23 -0800 Subject: [PATCH 01/23] added inspect of .Config.Volumes --- samba/setup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samba/setup.sh b/samba/setup.sh index cee38c4..859946e 100755 --- a/samba/setup.sh +++ b/samba/setup.sh @@ -87,6 +87,8 @@ if [ -z "$container" ]; then usage fi +$docker inspect --format="{{range \$k,\$v := .Config.Volumes}}{{println \$k}}{{end}}" $container > /inspect + if ! $docker inspect --format="{{range \$k,\$v := .Volumes}}{{println \$k}}{{end}}" $container > /inspect; then echo "Error: $container is not a valid container name: $_" usage From 9670ab2d3c1555c72b7f3c4b3332b52062d28a20 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 02:25:04 -0800 Subject: [PATCH 02/23] 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 1d052851150f6f2c3b105bf254b8d02199501555 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 03:31:52 -0800 Subject: [PATCH 03/23] 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 3e8fa813c47b46fc06793b69506bf19b4ae8c692 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 03:37:14 -0800 Subject: [PATCH 04/23] 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 aa2dbb3319466d3f501e70bad2afa9f313a546ce Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:11:54 -0800 Subject: [PATCH 05/23] 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 c33cf226c4a63352bf4f9be78ffe10fc6d85ddee Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:31:03 -0800 Subject: [PATCH 06/23] 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 7f3be571987fd64e1fd5ee517d05f9079981afe9 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:40:14 -0800 Subject: [PATCH 07/23] 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 9ce11ad529ada0499cd453180a02a2ce160118a7 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:40:34 -0800 Subject: [PATCH 08/23] 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 c2e5550e1fdaaa13bd1fe2adec4a96038f94dcfe Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:41:31 -0800 Subject: [PATCH 09/23] 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 6cb96be7ceeb7f1d065fcb4ae955578267865f45 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:44:39 -0800 Subject: [PATCH 10/23] 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 35c4b4dbb72054f69fa2ad726731a2ee1b818678 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 04:53:18 -0800 Subject: [PATCH 11/23] 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 b80f3463ce86775c185714cfc82cf4f1a1e70196 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 13:52:13 +0100 Subject: [PATCH 12/23] 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). From a6e9c7bb7839fc8b28dbd9d29f24435b70a8ce4a Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 10:40:38 -0800 Subject: [PATCH 13/23] added RUN_ARGUMENTS --- samba-share/setup-samba-share.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index 71f36fa..f08cb47 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -70,11 +70,12 @@ docker_host_execute "sambaContainer=`grep cpu[^a-zA-Z\d] /proc/1/cgroup | grep - # 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" -docker_host_execute "PASSWORD=$PASSWORD" -docker_host_execute "USERID=$USERID" -docker_host_execute "GROUP=$GROUP" -docker_host_execute "READONLY=$READONLY" +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\"" +docker_host_execute "RUN_ARGUMENTS=\"$RUN_ARGUMENTS\"" # define function for sh instead of a string for better syntax highlighting execute_in_sh() { @@ -126,6 +127,10 @@ execute_in_sh() { fi echo "Starting \"$server_container_name\" container sharing the volumes" $volumes "of container \"${container}\"." + if [ -n "$RUN_ARGUMENTS" ] + then + echo "\$RUN_ARGUMENTS: "$RUN_ARGUMENTS + fi # 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 @@ -135,6 +140,7 @@ execute_in_sh() { --expose 139 -p 139:139 \ --expose 445 -p 445:445 \ -e USER -e PASSWORD -e USERID -e GROUP -e READONLY \ + $RUN_ARGUMENTS \ --volumes-from "$container" \ "$sambaImage" --start "$container" $volumes > /dev/null 2>&1& From 8286ad2b6c5a77d759cccd9341d23b3b9df726a2 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 11:23:07 -0800 Subject: [PATCH 14/23] described arguments of samba-share --- samba-share/README.md | 18 +++++++++++++++--- samba-share/setup-samba-share.sh | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/samba-share/README.md b/samba-share/README.md index d2589ab..964416c 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -13,9 +13,21 @@ 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 +- 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 RUN_ARGUMENTS. Examples: + + # run a samba server in read only mode + docker run -e READONLY=yes niccokunzmann/samba-share | sh + # run a samba server on the host and share the content to other computers + docker run -e RUN_ARGUMENTS="--net=host" niccokunzmann/samba-share | sh + + - USER is the samba user (default: "root") + - PASSWORD is USER's password (default: "tcuser") + - USERID to use for the samba USER (default: "1000") + - GROUP user group (default: "root") + - READONLY "yes" or "no" whether write access is granted (default: "no") + - RUN_ARGUMENTS which additional arguments to pass to the `docker run ... samba-server` (default: "") + + Warning: If you use a `\` in these variables, it could be removed or unescaped. ## Try it out diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index f08cb47..bc904b1 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -34,13 +34,13 @@ usage() { # remove the default shell print docker_host_execute PS1= -docker_host_execute " +docker_host_execute ' output() { echo "$@" } docker_host_execute() { true -}" +}' # copy functions to sh From c86278b3118df4c46b9c60a46274efc6263ae2f0 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 14 Dec 2015 11:25:25 -0800 Subject: [PATCH 15/23] 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 964416c..15d4f37 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -24,7 +24,7 @@ Possible scenarios are - PASSWORD is USER's password (default: "tcuser") - USERID to use for the samba USER (default: "1000") - GROUP user group (default: "root") - - READONLY "yes" or "no" whether write access is granted (default: "no") + - READONLY "yes" or "no" whether write access is denied (default: "no") - RUN_ARGUMENTS which additional arguments to pass to the `docker run ... samba-server` (default: "") Warning: If you use a `\` in these variables, it could be removed or unescaped. From f1db78cb9f8fb0acabafdf9e81392aaaccad923b Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 16 Dec 2015 21:03:37 +0100 Subject: [PATCH 16/23] fixed typo --- samba-share/setup-samba-share.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index bc904b1..801a107 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -161,7 +161,7 @@ execute_in_sh() { 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 " enter 'cifs://$example_ip'" echo " hit the 'Connect' button" echo " select the volumes you want to mount" echo " choose the 'Guest' radiobox and connect" From d64b2c58ef9ddcfbef271f0bf73f2dbbbd240320 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 16 Dec 2015 16:18:23 -0800 Subject: [PATCH 17/23] tackled issue https://github.com/docker/docker/issues/17691#issuecomment-165269707 --- samba-share/rebuild.sh | 15 ++++ samba-share/samba-share.sh | 7 +- samba-share/setup-samba-share.sh | 130 ++++++++++++++++++++----------- 3 files changed, 104 insertions(+), 48 deletions(-) create mode 100755 samba-share/rebuild.sh diff --git a/samba-share/rebuild.sh b/samba-share/rebuild.sh new file mode 100755 index 0000000..586cc1e --- /dev/null +++ b/samba-share/rebuild.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +server_container_id=`docker ps -qa --filter label=samba-server` + +if [ -n "$server_container_id" ] +then + docker unpause $server_container_id + docker stop $server_container_id + docker rm $server_container_id + echo --------------------------------------------- +fi + +docker rmi niccokunzmann/samba-share +cd `dirname $0` +docker build -t niccokunzmann/samba-share . diff --git a/samba-share/samba-share.sh b/samba-share/samba-share.sh index 655e888..a9d6c2d 100755 --- a/samba-share/samba-share.sh +++ b/samba-share/samba-share.sh @@ -1,6 +1,11 @@ #!/bin/bash #set -e +volume_name_of() { + # also in setup-samba-share.sh + echo "$1" | sed "s/\///" | tr '[\/<>:"\\|?*+;,=]' '_' +} + USER=${USER:-"root"} PASSWORD=${PASSWORD:-"tcuser"} USERID=${USERID:-1000} @@ -19,7 +24,7 @@ for VOLUME in "$@" do echo "Adding volume \"$VOLUME\"." - VOLUME_NAME=`echo "$VOLUME" | sed "s/\///" | tr '[\/<>:"\\|?*+;,=]' '_'` + VOLUME_NAME=`volume_name_of $VOLUME` echo "[$VOLUME_NAME] comment = ${VOLUME_NAME} volume from ${CONTAINER} diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index bc904b1..40c037e 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -1,6 +1,10 @@ #!/bin/bash set -e +volume_name_of() { + # also in samba-share.sh + echo "$1" | sed "s/\///" | tr '[\/<>:"\\|?*+;,=]' '_' +} docker_host_execute() { echo "$@" } @@ -27,8 +31,13 @@ usage() { print_usage output docker_host_execute exit 1 + docker_host_execute exit 1 } +print_container_parameter_missing() { + container="" + usage "No container name given. Replace with the name of the container to share volumes from." +} # remove the default shell print @@ -48,6 +57,8 @@ docker_host_execute() { declare -f usage declare -f print_usage declare -f error +declare -f print_container_parameter_missing +declare -f volume_name_of # parse parameters container=$1 @@ -55,14 +66,25 @@ container=$1 # check parameters if [ -z "$container" ] then - # 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 "No container name given. Replace with the name of the container to share volumes from." + docker_host_execute print_container_parameter_missing + output() { + echo "# $@" + } + print_container_parameter_missing + exit 1 fi +# named run could fail due to this bug: +# https://github.com/docker/docker/issues/17691#issuecomment-165269707 +# using labels instead +server_container_label=samba-server + +server_container_ids() { + $DOCKER ps -qa --filter label="$server_container_label" +} +docker_host_execute "server_container_label=$server_container_label" +declare -f server_container_ids + # 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}'`" @@ -117,16 +139,24 @@ execute_in_sh() { exit 1 fi - server_container_name=samba-server - - if $DOCKER inspect --format "{{.State.Running}}" "$server_container_name" >/dev/null 2>&1 + # remove existing containers as they could block the ports + previous_container_ids=`server_container_ids` + if [ -n "$previous_container_ids" ] >/dev/null 2>&1 + then + echo "Stopping and removing existing servers." + $DOCKER unpause $previous_container_ids > /dev/null 2>&1 + $DOCKER stop $previous_container_ids > /dev/null 2>&1 + $DOCKER rm $previous_container_ids >/dev/null 2>&1 + fi + + # make sure we have no other containers running + still_existing_container_ids=`server_container_ids` + if [ -n "$still_existing_container_ids" ] 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 + echo "WARNING: these containers still exist but should not:" $still_existing_container_ids fi - echo "Starting \"$server_container_name\" container sharing the volumes" $volumes "of container \"${container}\"." + echo "Starting container with label \"$server_container_label\" sharing the volumes" $volumes "of container \"${container}\"." if [ -n "$RUN_ARGUMENTS" ] then echo "\$RUN_ARGUMENTS: "$RUN_ARGUMENTS @@ -134,15 +164,16 @@ 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" \ - --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 \ - $RUN_ARGUMENTS \ - --volumes-from "$container" \ - "$sambaImage" --start "$container" $volumes > /dev/null 2>&1& + { $DOCKER run --rm --label "$server_container_label" \ + --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 \ + $RUN_ARGUMENTS \ + --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 @@ -150,32 +181,37 @@ execute_in_sh() { # give advice # http://stackoverflow.com/a/20686101 - ips="`docker inspect --format ' {{ .NetworkSettings.IPAddress }}' "$server_container_name"`" + server_container_id=`server_container_ids | head -n1` + server_container_name=`docker inspect --format '{{.Name}}' $server_container_id | grep -o -E '[^/].*'` + ips="`docker inspect --format ' {{ .NetworkSettings.IPAddress }}' "$server_container_id"`" example_ip="`echo "$ips" | head -n1 | grep -o -E '\S+'`" - echo "" - echo "# run 'docker logs \"$server_container_name\"' to view the samba logs" - echo "" - echo "================================================" - echo "" - 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" - 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 "" + example_volume=`echo $volumes | head -n1` + example_volume_name=`volume_name_of "$example_volume"` + echo "" + echo "# run 'docker logs \"$server_container_name\"' to view the samba logs" + echo "" + echo "================================================" + echo "" + 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" + 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 " execute 'sudo mount -t cifs \"//$example_ip/$example_volume_name\" \"/mnt/$example_volume_name\" -o username=guest'" + echo " or open 'smb://$example_ip/' in the File Manager" + echo + echo "Or on Windows:" + echo " Enter '\\\\\\\\$example_ip\' into Explorer" + echo " Log in as Guest - no password" + echo "" + echo "Ip addresses: " + echo "$ips" + echo "" exit 0 } From 27300d146e328f4714b9b5d252fa2ff5b4f94dba Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 16 Dec 2015 16:28:17 -0800 Subject: [PATCH 18/23] made sharing volumes with spaces possible --- samba-share/samba-share.sh | 6 ++++-- samba-share/setup-samba-share.sh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/samba-share/samba-share.sh b/samba-share/samba-share.sh index a9d6c2d..9de12d6 100755 --- a/samba-share/samba-share.sh +++ b/samba-share/samba-share.sh @@ -13,14 +13,16 @@ GROUP=${GROUP:-"root"} READONLY=${READONLY:-"no"} CONTAINER="$1" -shift 1 +VOLUMES="$2" echo "Setting loglevel to 0." sed 's/\[global\]/\[global\]\n log level = 0/' -i.bak /etc/samba/smb.conf echo "Setting up samba configuration for container \"$CONTAINER\" and volumes "$@"." -for VOLUME in "$@" +IFS="\n" + +for VOLUME in $VOLUMES do echo "Adding volume \"$VOLUME\"." diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index c75b551..6f9d44a 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -172,7 +172,7 @@ execute_in_sh() { -e USER -e PASSWORD -e USERID -e GROUP -e READONLY \ $RUN_ARGUMENTS \ --volumes-from "$container" \ - "$sambaImage" --start "$container" $volumes > /dev/null 2>&1 & \ + "$sambaImage" --start "$container" "$volumes" > /dev/null 2>&1 & \ } # wait for the container to finish and remove it From 4ce1fe4d84d625ae25e4f75d67bcb31621dbb210 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Wed, 16 Dec 2015 16:49:12 -0800 Subject: [PATCH 19/23] made using spaces in folder names possible --- samba-share/samba-share.sh | 4 +++- samba-share/setup-samba-share.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/samba-share/samba-share.sh b/samba-share/samba-share.sh index 9de12d6..e6f4e78 100755 --- a/samba-share/samba-share.sh +++ b/samba-share/samba-share.sh @@ -20,7 +20,9 @@ sed 's/\[global\]/\[global\]\n log level = 0/' -i.bak /etc/samba/smb.conf echo "Setting up samba configuration for container \"$CONTAINER\" and volumes "$@"." -IFS="\n" +# looping through newline separated values +# http://superuser.com/questions/284187/bash-iterating-over-lines-in-a-variable +IFS=$'\n' for VOLUME in $VOLUMES do diff --git a/samba-share/setup-samba-share.sh b/samba-share/setup-samba-share.sh index 6f9d44a..a194e5e 100755 --- a/samba-share/setup-samba-share.sh +++ b/samba-share/setup-samba-share.sh @@ -185,7 +185,7 @@ execute_in_sh() { server_container_name=`docker inspect --format '{{.Name}}' $server_container_id | grep -o -E '[^/].*'` ips="`docker inspect --format ' {{ .NetworkSettings.IPAddress }}' "$server_container_id"`" example_ip="`echo "$ips" | head -n1 | grep -o -E '\S+'`" - example_volume=`echo $volumes | head -n1` + example_volume=`echo "$volumes" | head -n1` example_volume_name=`volume_name_of "$example_volume"` echo "" echo "# run 'docker logs \"$server_container_name\"' to view the samba logs" From 02bae4b2992b2a9ec7909b013997dcc116b5cb25 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Fri, 18 Dec 2015 00:02:09 +0100 Subject: [PATCH 20/23] changed hadings --- samba-share/README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/samba-share/README.md b/samba-share/README.md index 15d4f37..de815f5 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -1,13 +1,15 @@ -# Samba Docker volume sharing plugin +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 +Usage +----- Possible scenarios are @@ -29,7 +31,8 @@ Possible scenarios are Warning: If you use a `\` in these variables, it could be removed or unescaped. -## Try it out +Try it out +---------- Create a volume in my-data and share its content via samba @@ -38,13 +41,15 @@ Create a volume in my-data and share its content via samba # Share it using Samba (Windows file sharing) docker run niccokunzmann/samba-share my-data | sh -## How it works +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. -## Tested +Tested +------ - Client: @@ -63,6 +68,7 @@ that is `--volumes-from` setup to give it access. Built: Fri Nov 20 13:20:08 UTC 2015 OS/Arch: linux/amd64 -## Credits +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). From 6dea8f78256827e03c6ccf3a91fd6fccf4dd0a9e Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Fri, 18 Dec 2015 00:09:55 +0100 Subject: [PATCH 21/23] removed maintainer --- samba-share/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samba-share/Dockerfile b/samba-share/Dockerfile index 2715448..15ea315 100644 --- a/samba-share/Dockerfile +++ b/samba-share/Dockerfile @@ -2,8 +2,7 @@ FROM debian:stable 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) +MAINTAINER Nicco Kunzmann github.com/niccokunzmann # gettext for envsubst RUN apt-get update && \ From f5f60ceeeeb60652a75efb7d9ac282c55adabc08 Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Fri, 18 Dec 2015 00:18:01 +0100 Subject: [PATCH 22/23] added twitter --- samba-share/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samba-share/Dockerfile b/samba-share/Dockerfile index 15ea315..a70f705 100644 --- a/samba-share/Dockerfile +++ b/samba-share/Dockerfile @@ -2,7 +2,7 @@ FROM debian:stable 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 Nicco Kunzmann github.com/niccokunzmann +MAINTAINER Nicco Kunzmann github.com/niccokunzmann @dannhaltohneson # gettext for envsubst RUN apt-get update && \ From 280c72d3b713bfdc8b00aad02e00099a807a1a8b Mon Sep 17 00:00:00 2001 From: Nicco Kunzmann Date: Mon, 21 Dec 2015 15:47:01 +0100 Subject: [PATCH 23/23] Update README.md --- samba-share/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/samba-share/README.md b/samba-share/README.md index de815f5..e20a483 100644 --- a/samba-share/README.md +++ b/samba-share/README.md @@ -45,7 +45,7 @@ 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 +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 @@ -72,3 +72,6 @@ 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). + + +