From 6c8f80b326a8d2172e37c9077f2dac6c67478010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Sat, 9 Jan 2021 22:32:52 +0100 Subject: [PATCH] Configurable IP address used to bind apps' ports --- common/config.go | 3 ++- docker/docker.go | 8 +++++--- docker/types.go | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/config.go b/common/config.go index aabec34..69b30d0 100644 --- a/common/config.go +++ b/common/config.go @@ -8,7 +8,8 @@ import ( // Config keeps info about configuration of this daemon type Config struct { - AppsPath string `envconfig:"APPS_PATH" default:"/srv"` // Where applications are located + AppsPath string `envconfig:"APPS_PATH" default:"/srv"` // Where applications are located + AppsBindIP string `envconfig:"APPS_BIND_IP" default:"0.0.0.0"` // On what IP apps gonna be bound } // GetConfig return configuration created based on environment variables diff --git a/docker/docker.go b/docker/docker.go index 2f47925..c6a9afd 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -33,7 +33,9 @@ const podmanSock = "/run/podman/podman.sock" const dockerAPIVersion = "1.38" // Driver keeps everything for connection to Docker -type Driver struct{} +type Driver struct { + BindIP string // IP to which containers are bound +} func (d *Driver) getClient() (*dockerClient.Client, error) { var connectTo string @@ -318,7 +320,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i portBindings := nat.PortMap{ "8000/tcp": []nat.PortBinding{ { - HostIP: "0.0.0.0", + HostIP: d.BindIP, HostPort: strconv.Itoa(HTTPPort), }, }, @@ -327,7 +329,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i if SSHPort != 0 { portBindings["22/tcp"] = []nat.PortBinding{ { - HostIP: "0.0.0.0", + HostIP: d.BindIP, HostPort: strconv.Itoa(SSHPort), }, } diff --git a/docker/types.go b/docker/types.go index 40f522e..b919dc7 100644 --- a/docker/types.go +++ b/docker/types.go @@ -25,7 +25,10 @@ type Container struct { } func (c *Container) getDriver() *Driver { - driver := &Driver{} + config := common.GetConfig() + driver := &Driver{ + BindIP: config.AppsBindIP, + } return driver }