First pass at passing DOCKER_HOST=unix://* through to the weave and proxy
This commit is contained in:
1 parent
ca1cce3232
commit
0afc3db383
4 files changed
+41
-12
No files matched your search
@@ -12,7 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "(unreleased version)"
|
version = "(unreleased version)"
|
||||||
|
defaultDockerHost = "unix:///var/run/docker.sock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -61,6 +62,11 @@ func main() {
|
|||||||
Log.Infoln("weave proxy", version)
|
Log.Infoln("weave proxy", version)
|
||||||
Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " "))
|
Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " "))
|
||||||
|
|
||||||
|
c.DockerHost = defaultDockerHost
|
||||||
|
if dockerHost := os.Getenv("DOCKER_HOST"); dockerHost != "" {
|
||||||
|
c.DockerHost = dockerHost
|
||||||
|
}
|
||||||
|
|
||||||
p, err := proxy.NewProxy(c)
|
p, err := proxy.NewProxy(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Fatalf("Could not start proxy: %s", err)
|
Log.Fatalf("Could not start proxy: %s", err)
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ func callWeave(args ...string) ([]byte, []byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
propagateEnv("DOCKER_BRIDGE")
|
propagateEnv("DOCKER_BRIDGE")
|
||||||
|
propagateEnv("DOCKER_HOST")
|
||||||
|
|
||||||
// Propogage WEAVE_DEBUG, to make debugging easier.
|
// Propogage WEAVE_DEBUG, to make debugging easier.
|
||||||
propagateEnv("WEAVE_DEBUG")
|
propagateEnv("WEAVE_DEBUG")
|
||||||
|
|||||||
+16
-6
@@ -25,8 +25,6 @@ const (
|
|||||||
defaultCaFile = "ca.pem"
|
defaultCaFile = "ca.pem"
|
||||||
defaultKeyFile = "key.pem"
|
defaultKeyFile = "key.pem"
|
||||||
defaultCertFile = "cert.pem"
|
defaultCertFile = "cert.pem"
|
||||||
dockerSock = "/var/run/docker.sock"
|
|
||||||
dockerSockUnix = "unix://" + dockerSock
|
|
||||||
|
|
||||||
weaveSock = "/var/run/weave/weave.sock"
|
weaveSock = "/var/run/weave/weave.sock"
|
||||||
weaveSockUnix = "unix://" + weaveSock
|
weaveSockUnix = "unix://" + weaveSock
|
||||||
@@ -61,6 +59,7 @@ type Config struct {
|
|||||||
WithDNS bool
|
WithDNS bool
|
||||||
WithoutDNS bool
|
WithoutDNS bool
|
||||||
NoMulticastRoute bool
|
NoMulticastRoute bool
|
||||||
|
DockerHost string
|
||||||
}
|
}
|
||||||
|
|
||||||
type wait struct {
|
type wait struct {
|
||||||
@@ -94,7 +93,7 @@ func NewProxy(c Config) (*Proxy, error) {
|
|||||||
// to insulate ourselves from breaking changes to the API, as
|
// to insulate ourselves from breaking changes to the API, as
|
||||||
// happened in 1.20 (Docker 1.8.0) when the presentation of
|
// happened in 1.20 (Docker 1.8.0) when the presentation of
|
||||||
// volumes changed in `inspect`.
|
// volumes changed in `inspect`.
|
||||||
client, err := weavedocker.NewVersionedClient(dockerSockUnix, "1.18")
|
client, err := weavedocker.NewVersionedClient(c.DockerHost, "1.18")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -140,7 +139,16 @@ func (proxy *Proxy) AttachExistingContainers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) Dial() (net.Conn, error) {
|
func (proxy *Proxy) Dial() (net.Conn, error) {
|
||||||
return net.Dial("unix", dockerSock)
|
proto := "tcp"
|
||||||
|
addr := proxy.Config.DockerHost
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(addr, "unix://"):
|
||||||
|
proto = "unix"
|
||||||
|
addr = strings.TrimPrefix(addr, "unix://")
|
||||||
|
case strings.HasPrefix(addr, "tcp://"):
|
||||||
|
addr = strings.TrimPrefix(addr, "tcp://")
|
||||||
|
}
|
||||||
|
return net.Dial(proto, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) findWeaveWaitVolumes() error {
|
func (proxy *Proxy) findWeaveWaitVolumes() error {
|
||||||
@@ -321,8 +329,10 @@ func (proxy *Proxy) listen(protoAndAddr string) (net.Listener, string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
if err = copyOwnerAndPermissions(dockerSock, addr); err != nil {
|
if strings.HasPrefix(proxy.Config.DockerHost, "unix://") {
|
||||||
return nil, "", err
|
if err = copyOwnerAndPermissions(strings.TrimPrefix(proxy.Config.DockerHost, "unix://"), addr); err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -96,9 +96,21 @@ usage() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docker_sock() {
|
||||||
|
if echo "$DOCKER_HOST" | grep -q "^unix://" >/dev/null; then
|
||||||
|
echo "${DOCKER_HOST#unix://}"
|
||||||
|
else
|
||||||
|
echo "/var/run/docker.sock"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
docker_sock_volume_mount() {
|
||||||
|
echo "-v $(docker_sock):$(docker_sock) -e DOCKER_HOST=unix://$(docker_sock)"
|
||||||
|
}
|
||||||
|
|
||||||
exec_remote() {
|
exec_remote() {
|
||||||
docker $DOCKER_CLIENT_ARGS run --rm --privileged --net=host \
|
docker $DOCKER_CLIENT_ARGS run --rm --privileged --net=host \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
$(docker_sock_volume_mount) \
|
||||||
-v /proc:/hostproc \
|
-v /proc:/hostproc \
|
||||||
-e PROCFS=/hostproc \
|
-e PROCFS=/hostproc \
|
||||||
-e DOCKERHUB_USER="$DOCKERHUB_USER" \
|
-e DOCKERHUB_USER="$DOCKERHUB_USER" \
|
||||||
@@ -1609,7 +1621,7 @@ launch_router() {
|
|||||||
# additional parameters, such as resource limits, to docker
|
# additional parameters, such as resource limits, to docker
|
||||||
# when launching the weave container.
|
# when launching the weave container.
|
||||||
ROUTER_CONTAINER=$(docker run --privileged -d --name=$CONTAINER_NAME \
|
ROUTER_CONTAINER=$(docker run --privileged -d --name=$CONTAINER_NAME \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
$(docker_sock_volume_mount) \
|
||||||
-p $PORT:$CONTAINER_PORT/tcp -p $PORT:$CONTAINER_PORT/udp \
|
-p $PORT:$CONTAINER_PORT/tcp -p $PORT:$CONTAINER_PORT/udp \
|
||||||
${NETHOST_OPT:-$DNS_PORT_MAPPING} \
|
${NETHOST_OPT:-$DNS_PORT_MAPPING} \
|
||||||
-e WEAVE_PASSWORD \
|
-e WEAVE_PASSWORD \
|
||||||
@@ -1621,7 +1633,7 @@ launch_router() {
|
|||||||
--dns-effective-listen-address $DOCKER_BRIDGE_IP \
|
--dns-effective-listen-address $DOCKER_BRIDGE_IP \
|
||||||
${NETHOST_OPT:+$DNS_ROUTER_OPTS} $NO_DNS_OPT \
|
${NETHOST_OPT:+$DNS_ROUTER_OPTS} $NO_DNS_OPT \
|
||||||
--http-addr $HTTP_IP:$HTTP_PORT \
|
--http-addr $HTTP_IP:$HTTP_PORT \
|
||||||
--docker-api "unix:///var/run/docker.sock" "$@")
|
--docker-api "unix://$(docker_sock)" "$@")
|
||||||
with_container_netns_or_die $CONTAINER_NAME setup_router_iface_$BRIDGE_TYPE
|
with_container_netns_or_die $CONTAINER_NAME setup_router_iface_$BRIDGE_TYPE
|
||||||
attach_router
|
attach_router
|
||||||
}
|
}
|
||||||
@@ -1666,7 +1678,7 @@ launch_proxy() {
|
|||||||
mkdir -p /var/run/weave
|
mkdir -p /var/run/weave
|
||||||
PROXY_CONTAINER=$(docker run --privileged -d --name=$PROXY_CONTAINER_NAME --net=host \
|
PROXY_CONTAINER=$(docker run --privileged -d --name=$PROXY_CONTAINER_NAME --net=host \
|
||||||
$PROXY_VOLUMES \
|
$PROXY_VOLUMES \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
$(docker_sock_volume_mount) \
|
||||||
-v /var/run/weave:/var/run/weave \
|
-v /var/run/weave:/var/run/weave \
|
||||||
-v /proc:/hostproc \
|
-v /proc:/hostproc \
|
||||||
-e PROCFS=/hostproc \
|
-e PROCFS=/hostproc \
|
||||||
@@ -1689,7 +1701,7 @@ launch_plugin() {
|
|||||||
PLUGIN_CONTAINER=$(docker run --privileged -d --name=$PLUGIN_CONTAINER_NAME \
|
PLUGIN_CONTAINER=$(docker run --privileged -d --name=$PLUGIN_CONTAINER_NAME \
|
||||||
--restart=always \
|
--restart=always \
|
||||||
--net=host \
|
--net=host \
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
$(docker_sock_volume_mount) \
|
||||||
-v /run/docker/plugins:/run/docker/plugins \
|
-v /run/docker/plugins:/run/docker/plugins \
|
||||||
$PLUGIN_IMAGE "$@")
|
$PLUGIN_IMAGE "$@")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user