mirror of
https://github.com/unraid/webgui.git
synced 2026-04-23 10:38:50 -05:00
Docker support custom bridge networks without port bindings
This commit is contained in:
@@ -31,10 +31,8 @@ $DockerTemplates = new DockerTemplates();
|
||||
|
||||
$custom = DockerUtil::docker("network ls --filter driver='bridge' --filter driver='macvlan' --format='{{.Name}}'|grep -v '^bridge$'",true);
|
||||
$subnet = ['bridge'=>'', 'host'=>'', 'none'=>''];
|
||||
$driver = [];
|
||||
|
||||
foreach ($custom as $network) $subnet[$network] = substr(DockerUtil::docker("network inspect --format='{{range .IPAM.Config}}{{.Subnet}}, {{end}}' $network"),0,-1);
|
||||
foreach (DockerUtil::docker("network ls --format='{{.Name}}|{{.Driver}}'",true) as $network) {list($name,$type) = explode('|',$network); $driver[$name] = $type;}
|
||||
|
||||
function stopContainer($name) {
|
||||
global $DockerClient;
|
||||
@@ -564,9 +562,7 @@ if (isset($_POST['contName'])) {
|
||||
// remove old template
|
||||
@unlink("$userTmplDir/my-$existing.xml");
|
||||
}
|
||||
if ($startContainer) {
|
||||
$cmd = str_replace('/plugins/dynamix.docker.manager/scripts/docker create ', '/plugins/dynamix.docker.manager/scripts/docker run -d ', $cmd);
|
||||
}
|
||||
if ($startContainer) $cmd = str_replace('/docker create ', '/docker run -d ', $cmd);
|
||||
execCommand($cmd);
|
||||
echo '<div style="text-align:center"><button type="button" onclick="done()">Done</button></div><br>';
|
||||
goto END;
|
||||
|
||||
@@ -31,9 +31,11 @@ $dockerManPaths = [
|
||||
if (!isset($eth0)) extract(parse_ini_file("$docroot/state/network.ini",true));
|
||||
$host = $eth0['IPADDR:0'] ?? '0.0.0.0';
|
||||
|
||||
// get network drivers
|
||||
$driver = DockerUtil::driver();
|
||||
|
||||
// Docker configuration file - guaranteed to exist
|
||||
$docker_cfgfile = '/boot/config/docker.cfg';
|
||||
$dockercfg = parse_ini_file($docker_cfgfile);
|
||||
$dockercfg = parse_ini_file('/boot/config/docker.cfg');
|
||||
|
||||
#######################################
|
||||
## DOCKERTEMPLATES CLASS ##
|
||||
@@ -698,6 +700,7 @@ class DockerClient {
|
||||
}
|
||||
|
||||
public function getDockerContainers() {
|
||||
global $driver;
|
||||
// Return cached values
|
||||
if (is_array($this::$containersCache)) return $this::$containersCache;
|
||||
$this::$containersCache = [];
|
||||
@@ -717,7 +720,7 @@ class DockerClient {
|
||||
$c['NetworkMode'] = $ct['HostConfig']['NetworkMode'];
|
||||
$c['BaseImage'] = $ct['Labels']['BASEIMAGE'] ?? false;
|
||||
$c['Ports'] = [];
|
||||
if (!empty($info['HostConfig']['PortBindings'])) {
|
||||
if ($driver[$c['NetworkMode']]=='bridge') {
|
||||
$ports = &$info['HostConfig']['PortBindings'];
|
||||
$nat = true;
|
||||
} else {
|
||||
@@ -819,5 +822,10 @@ class DockerUtil {
|
||||
$ipaddr = $version==4 ? 'IPAddress' : 'GlobalIPv6Address';
|
||||
return static::docker("inspect --format='{{range .NetworkSettings.Networks}}{{.$ipaddr}}{{end}}' $name");
|
||||
}
|
||||
public static function driver() {
|
||||
$list = [];
|
||||
foreach (static::docker("network ls --format='{{.Name}}={{.Driver}}'",true) as $network) {list($name,$driver) = explode('=',$network); $list[$name] = $driver;}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user