Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the ability to bind to a Unix socket #141

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ For example, [balenaOS](https://www.balena.io/os/) exposes its socket at
`/var/run/balena-engine.sock`. To accommodate this, merely set the `SOCKET_PATH`
environment variable to `/var/run/balena-engine.sock`.

## Exposing as a Unix socket

If you'd like to expose the proxy as a Unix socket, you can do so by setting the
`BIND_CONFIG` environment variable.

As an example, the following command will start the proxy and bind to the socket at
`/sockets/docker.sock`. Since this is a volume, this could then be shared with another
container.

```
$ docker container run \
-d --privileged \
--name dockerproxy \
-v /var/run/docker.sock:/var/run/docker.sock \
-v docker-socket:/sockets \
-e BIND_CONFIG=/sockets/docker.sock \
tecnativa/docker-socket-proxy
```

Once running, the socket can be shared with another container by using the
`docker-socket` volume:

```
$ docker container run -v docker-socket:/var/run ...
```

## Development

All the dependencies you need to develop this project (apart from Docker itself) are
Expand Down
26 changes: 14 additions & 12 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/bin/sh
set -e

# Normalize the input for DISABLE_IPV6 to lowercase
DISABLE_IPV6_LOWER=$(echo "$DISABLE_IPV6" | tr '[:upper:]' '[:lower:]')
if [ "${BIND_CONFIG}" = "" ]; then
# Normalize the input for DISABLE_IPV6 to lowercase
DISABLE_IPV6_LOWER=$(echo "$DISABLE_IPV6" | tr '[:upper:]' '[:lower:]')

# Check for different representations of 'true' and set BIND_CONFIG
case "$DISABLE_IPV6_LOWER" in
1|true|yes)
BIND_CONFIG=":2375"
;;
*)
BIND_CONFIG="[::]:2375 v4v6"
;;
esac
# Check for different representations of 'true' and set BIND_CONFIG
case "$DISABLE_IPV6_LOWER" in
1|true|yes)
BIND_CONFIG=":2375"
;;
*)
BIND_CONFIG="[::]:2375 v4v6"
;;
esac
fi

# Process the HAProxy configuration template using sed
sed "s/\${BIND_CONFIG}/$BIND_CONFIG/g" /usr/local/etc/haproxy/haproxy.cfg.template > /usr/local/etc/haproxy/haproxy.cfg
sed "s#/\${BIND_CONFIG}#$BIND_CONFIG#g" /usr/local/etc/haproxy/haproxy.cfg.template > /usr/local/etc/haproxy/haproxy.cfg

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
Expand Down
Loading