From 7321fe14217f8d2e22d512c190bf6b3427b3f75c Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 25 Apr 2020 12:18:18 -0700 Subject: [PATCH] Make DNS settings for containers configurable, closes #1965 --- config/config.go | 48 --------------------------------- config/config_docker.go | 52 ++++++++++++++++++++++++++++++++++++ server/environment_docker.go | 3 +-- 3 files changed, 53 insertions(+), 50 deletions(-) create mode 100644 config/config_docker.go diff --git a/config/config.go b/config/config.go index cd8133d..97ce852 100644 --- a/config/config.go +++ b/config/config.go @@ -98,54 +98,6 @@ type SftpConfiguration struct { ReadOnly bool `default:"false" yaml:"read_only"` } -type dockerNetworkInterfaces struct { - V4 struct { - Subnet string `default:"172.18.0.0/16"` - Gateway string `default:"172.18.0.1"` - } - - V6 struct { - Subnet string `default:"fdba:17c8:6c94::/64"` - Gateway string `default:"fdba:17c8:6c94::1011"` - } -} - -type DockerNetworkConfiguration struct { - // The interface that should be used to create the network. Must not conflict - // with any other interfaces in use by Docker or on the system. - Interface string `default:"172.18.0.1"` - - // The name of the network to use. If this network already exists it will not - // be created. If it is not found, a new network will be created using the interface - // defined. - Name string `default:"pterodactyl_nw"` - ISPN bool `default:"false" yaml:"ispn"` - Driver string `default:"bridge"` - IsInternal bool `default:"false" yaml:"is_internal"` - EnableICC bool `default:"true" yaml:"enable_icc"` - Interfaces dockerNetworkInterfaces `yaml:"interfaces"` -} - -// Defines the docker configuration used by the daemon when interacting with -// containers and networks on the system. -type DockerConfiguration struct { - // Network configuration that should be used when creating a new network - // for containers run through the daemon. - Network DockerNetworkConfiguration `json:"network" yaml:"network"` - - // If true, container images will be updated when a server starts if there - // is an update available. If false the daemon will not attempt updates and will - // defer to the host system to manage image updates. - UpdateImages bool `default:"true" json:"update_images" yaml:"update_images"` - - // The location of the Docker socket. - Socket string `default:"/var/run/docker.sock"` - - // Defines the location of the timezone file on the host system that should - // be mounted into the created containers so that they all use the same time. - TimezonePath string `default:"/etc/timezone" json:"timezone_path" yaml:"timezone_path"` -} - // Defines the configuration for the internal API that is exposed by the // daemon webserver. type ApiConfiguration struct { diff --git a/config/config_docker.go b/config/config_docker.go new file mode 100644 index 0000000..59de8a1 --- /dev/null +++ b/config/config_docker.go @@ -0,0 +1,52 @@ +package config + +type dockerNetworkInterfaces struct { + V4 struct { + Subnet string `default:"172.18.0.0/16"` + Gateway string `default:"172.18.0.1"` + } + + V6 struct { + Subnet string `default:"fdba:17c8:6c94::/64"` + Gateway string `default:"fdba:17c8:6c94::1011"` + } +} + +type DockerNetworkConfiguration struct { + // The interface that should be used to create the network. Must not conflict + // with any other interfaces in use by Docker or on the system. + Interface string `default:"172.18.0.1"` + + // The DNS settings for containers. + Dns []string `default:"[\"1.1.1.1\", \"1.0.0.1\"]"` + + // The name of the network to use. If this network already exists it will not + // be created. If it is not found, a new network will be created using the interface + // defined. + Name string `default:"pterodactyl_nw"` + ISPN bool `default:"false" yaml:"ispn"` + Driver string `default:"bridge"` + IsInternal bool `default:"false" yaml:"is_internal"` + EnableICC bool `default:"true" yaml:"enable_icc"` + Interfaces dockerNetworkInterfaces `yaml:"interfaces"` +} + +// Defines the docker configuration used by the daemon when interacting with +// containers and networks on the system. +type DockerConfiguration struct { + // Network configuration that should be used when creating a new network + // for containers run through the daemon. + Network DockerNetworkConfiguration `json:"network" yaml:"network"` + + // If true, container images will be updated when a server starts if there + // is an update available. If false the daemon will not attempt updates and will + // defer to the host system to manage image updates. + UpdateImages bool `default:"true" json:"update_images" yaml:"update_images"` + + // The location of the Docker socket. + Socket string `default:"/var/run/docker.sock"` + + // Defines the location of the timezone file on the host system that should + // be mounted into the created containers so that they all use the same time. + TimezonePath string `default:"/etc/timezone" json:"timezone_path" yaml:"timezone_path"` +} diff --git a/server/environment_docker.go b/server/environment_docker.go index 825289f..9df3b61 100644 --- a/server/environment_docker.go +++ b/server/environment_docker.go @@ -618,8 +618,7 @@ func (d *DockerEnvironment) Create() error { // from the Panel. Resources: d.getResourcesForServer(), - // @todo make this configurable again - DNS: []string{"1.1.1.1", "8.8.8.8"}, + DNS: config.Get().Docker.Network.Dns, // Configure logging for the container to make it easier on the Daemon to grab // the server output. Ensure that we don't use too much space on the host machine