Skip to content

Commit

Permalink
Try switching to running powerstrip on the Docker socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Marsden committed Feb 20, 2015
1 parent a0aaf02 commit 93f2981
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
27 changes: 16 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ Try it out

Powerstrip ships as a Docker image, and adapters can be any HTTP endpoint, including other linked Docker containers.

Powerstrip expects Docker to have been reconfigured to listen on ``/var/run/docker.real.sock``, and to have ``/var/run`` on the host bind-mounted in at ``/host-var-run``.

Reconfigure Docker in this way: for example on Ubuntu edit ``/etc/default/docker`` with ``-H unix:///var/run/docker.real.sock`` and then run ``sudo restart docker``.

This comment has been minimized.

Copy link
@binocarlos

binocarlos Feb 20, 2015

Contributor

Needs a note here that tells the user to sudo rm /var/run/docker.sock in case there is an existing socket from an old docker daemon

Powerstrip will then create ``/var/run/docker.sock`` from the host's perspective (``/host-var-run/docker.sock`` from inside its container) and normal Docker tools should carry on working as normal.

This comment has been minimized.

Copy link
@binocarlos

binocarlos Feb 20, 2015

Contributor

Needs a note that tells the user to sudo chgrp docker /var/run/docker.sock - it is group=root when created from inside the container.

`Slowreq <https://github.com/clusterhq/powerstrip-slowreq>`_ is a trivial Powerstrip adapter (container) which adds a 1 second delay to all create commands.

Try it out like this (assuming logged into an Ubuntu Docker host).
If you are using ``boot2docker``, who knows. XXX ???

If you are using ``boot2docker``, drop the ``sudo`` and also unset ``DOCKER_TLS_VERIFY``.
Try it out like this (assuming logged into an Ubuntu Docker host).

.. code:: sh
Expand All @@ -86,22 +92,21 @@ If you are using ``boot2docker``, drop the ``sudo`` and also unset ``DOCKER_TLS_
slowreq: http://slowreq/slowreq-adapter
EOF
$ sudo docker run -d --name powerstrip-slowreq \
$ sudo DOCKER_HOST="unix:///var/run/docker.real.sock" \
docker run -d --name powerstrip-slowreq \
--expose 80 \
clusterhq/powerstrip-slowreq:v0.0.1
$ sudo docker run -d --name powerstrip \
-v /var/run/docker.sock:/var/run/docker.sock \
$ sudo DOCKER_HOST="unix:///var/run/docker.real.sock" \
docker run -d --name powerstrip \
-v /var/run:/host-var-run \
-v $PWD/powerstrip-demo/adapters.yml:/etc/powerstrip/adapters.yml \
--link powerstrip-slowreq:slowreq \
-p 2375:2375 \
clusterhq/powerstrip:v0.0.1
clusterhq/powerstrip:unix-socket # XXX change this to v0.0.2 when releasing
# Note how the second command takes a second longer than the first.
$ time sudo DOCKER_HOST="unix:///var/run/docker.sock.real" \

This comment has been minimized.

Copy link
@tomdee

tomdee Mar 13, 2015

Shouldn't this be docker.real.sock

docker run ubuntu echo hello
$ time sudo docker run ubuntu echo hello
$ time DOCKER_HOST=localhost:2375 docker run ubuntu echo hello
**Warning:** Powerstrip exposes the Docker API unprotected on port 2375.
Only use it in private, secure development environments.
**Issues:** If you are using ``SELinux`` and having some issues, disable it or run the following commands:
Expand Down
11 changes: 7 additions & 4 deletions powerstrip.tac
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DOCKER_HOST = os.environ.get('DOCKER_HOST')
if DOCKER_HOST is None:
# Default to assuming we've got a Docker socket bind-mounted into a
# container we're running in.
DOCKER_HOST = "unix:///var/run/docker.sock"
DOCKER_HOST = "unix:///host-var-run/docker.real.sock"
if "://" not in DOCKER_HOST:
DOCKER_HOST = "tcp://" + DOCKER_HOST
if DOCKER_HOST.startswith("tcp://"):
Expand All @@ -22,7 +22,10 @@ elif DOCKER_HOST.startswith("unix://"):
socketPath = DOCKER_HOST[len("unix://"):]
dockerAPI = ServerProtocolFactory(dockerSocket=socketPath)
#logged = TrafficLoggingFactory(dockerAPI, "api-")
dockerServer = internet.TCPServer(2375, dockerAPI, interface='0.0.0.0')
dockerServer.setServiceParent(application)

print r'export DOCKER_HOST=tcp://localhost:2375'
# Refuse to listen on a TCP port, until
# https://github.com/ClusterHQ/powerstrip/issues/56 is resolved.
# TODO: maybe allow to specify a numberic Docker group (gid) as environment
# variable, and also (optionally) the name of the socket file it creates...
dockerServer = internet.UNIXServer("/host-var-run/docker.sock", dockerAPI, mode=0660)
dockerServer.setServiceParent(application)

0 comments on commit 93f2981

Please sign in to comment.