Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions samba-share/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 @dannhaltohneson

# gettext for envsubst
RUN apt-get update && \
apt-get install -yq samba gettext
ADD run.sh /run.sh
ADD setup-samba-share.sh /setup-samba-share.sh
ADD samba-share.sh /samba-share.sh

ENTRYPOINT ["/run.sh"]
77 changes: 77 additions & 0 deletions samba-share/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@


Samba Docker volume sharing plugin
==================================

Sharing a Docker container's volume should be as simple as `docker run niccokunzmann/samba-share <container> | 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 <container> | sh` shares the volumes of `<container>`.
- `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 RUN_ARGUMENTS. Examples:

# run a samba server in read only mode
docker run -e READONLY=yes niccokunzmann/samba-share <container> | 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 <container> | 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 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.

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.

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).



15 changes: 15 additions & 0 deletions samba-share/rebuild.sh
Original file line number Diff line number Diff line change
@@ -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 .
19 changes: 19 additions & 0 deletions samba-share/run.sh
Original file line number Diff line number Diff line change
@@ -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




57 changes: 57 additions & 0 deletions samba-share/samba-share.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/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}
GROUP=${GROUP:-"root"}
READONLY=${READONLY:-"no"}

CONTAINER="$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 "$@"."

# looping through newline separated values
# http://superuser.com/questions/284187/bash-iterating-over-lines-in-a-variable
IFS=$'\n'

for VOLUME in $VOLUMES
do
echo "Adding volume \"$VOLUME\"."

VOLUME_NAME=`volume_name_of $VOLUME`

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

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 removed by --rm.
exit 0

Loading