Browse code

Add target for `make run`

`make run` allows you to fire up a daemon (in a container) just using
the existing built binaries. This allows for more rapid iteration
instead of dealing with firing up a shell just to start the daemon.

By default the daemon will listen on port 2375 on the default network
interface.

If a port forward is required to access the daemon, the user can set
`make DOCKER_PORT=2375 run` to get a port forward on a random port with
the daemon listening on port 2375, or `make DOCKER_PORT=2375:2375 run`
to get a daemon running with port 2375 forwarded to the daemon running
on 2375.

Note that the daemon is automatically configured to listen on whatever
port is set for the container side of the `DOCKER_PORT` port spec.

When running on docker4mac, the user must do the following:
```
$ make BINDDIR=. DOCKER_PORT=2375 run
```

This makes sure the binaries are loaded in the container and a port is
forwarded, since it is currently impossible to route traffic from the
mac directly to a container IP.

To get a fresh binary:
```
$ make BINDDIR=. DOCKER_PORT=2375 binary run
```

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2016/07/08 05:01:44
Showing 2 changed files
... ...
@@ -20,6 +20,7 @@ DOCKER_ENVS := \
20 20
 	-e DOCKER_GITCOMMIT \
21 21
 	-e DOCKER_GRAPHDRIVER=$(DOCKER_GRAPHDRIVER) \
22 22
 	-e DOCKER_INCREMENTAL_BINARY \
23
+	-e DOCKER_PORT \
23 24
 	-e DOCKER_REMAP_ROOT \
24 25
 	-e DOCKER_STORAGE_OPTS \
25 26
 	-e DOCKER_USERLANDPROXY \
... ...
@@ -43,8 +44,9 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
43 43
 GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
44 44
 DOCKER_IMAGE := docker-dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
45 45
 DOCKER_DOCS_IMAGE := docker-docs$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
46
+DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",)
46 47
 
47
-DOCKER_FLAGS := docker run --rm -i --privileged $(DOCKER_ENVS) $(DOCKER_MOUNT)
48
+DOCKER_FLAGS := docker run --rm -i --privileged $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD)
48 49
 
49 50
 # if this session isn't interactive, then we don't want to allocate a
50 51
 # TTY, which would fail, but if it is interactive, we do want to attach
... ...
@@ -97,6 +99,9 @@ install: ## install the linux binaries
97 97
 rpm: build ## build the rpm packages
98 98
 	$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary build-rpm
99 99
 
100
+run: build ## run the docker daemon in a container
101
+	$(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run"
102
+
100 103
 shell: build ## start a shell inside the build env
101 104
 	$(DOCKER_RUN_DOCKER) bash
102 105
 
103 106
new file mode 100644
... ...
@@ -0,0 +1,44 @@
0
+#!/bin/bash
1
+
2
+set -e
3
+rm -rf "$DEST"
4
+
5
+if ! command -v dockerd &> /dev/null; then
6
+	echo >&2 'error: binary-daemon or dynbinary-daemon must be run before run'
7
+	false
8
+fi
9
+
10
+DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
11
+DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true}
12
+
13
+# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
14
+storage_params=""
15
+if [ -n "$DOCKER_STORAGE_OPTS" ]; then
16
+	IFS=','
17
+	for i in ${DOCKER_STORAGE_OPTS}; do
18
+		storage_params="--storage-opt $i $storage_params"
19
+	done
20
+	unset IFS
21
+fi
22
+
23
+
24
+listen_port=2375
25
+if [ -n "$DOCKER_PORT" ]; then
26
+	IFS=':' read -r -a ports <<< "$DOCKER_PORT"
27
+	listen_port="${ports[-1]}"
28
+fi
29
+
30
+extra_params=""
31
+if [ "$DOCKER_REMAP_ROOT" ]; then
32
+	extra_params="--userns-remap $DOCKER_REMAP_ROOT"
33
+fi
34
+
35
+args="--debug \
36
+	--host tcp://0.0.0.0:${listen_port} --host unix:///var/run/docker.sock \
37
+	--storage-driver "$DOCKER_GRAPHDRIVER" \
38
+	--userland-proxy="$DOCKER_USERLANDPROXY" \
39
+	$storage_params \
40
+	$extra_params"
41
+
42
+echo dockerd $args
43
+exec dockerd $args