diff --git a/README.md b/README.md index 4346c1a..98c6566 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,26 @@ Created to manage a local Docker install for a home server. Current supports: * Viewing docker system info * View, automatically refresh and filter container logs * View container properties +* 2 new monitor types for [System and server status](https://webmin.com/docs/modules/system-and-server-status/) - 'Docker Up' & 'Docker Container Up' Currently translated to English, Italian and Polish. UI is responsive across all device sizes. If you're after a full Docker web interface you should consider https://www.portainer.io or https://yacht.sh. ## How does it work? -It uses the Docker CLI and abuses the `--format {{}}` arg for output parsing. This should work for normal installs of docker - rootless docker and other alternative installs is currently not supported. +It uses the Docker CLI and abuses the `--format {{}}` arg for output parsing. This should work for normal installs of Docker and Rootless Docker installs where the webmin user has an appropriate Docker context and permissions applied (see [Rootless Docker](#rootless-docker)). + +For monitors checks, `docker info` is used to get the current Docker status to avoid complexities in determining how Docker is set to startup and run. Container health is checked via `docker container inspect`. ## Install The fastest way to install is to follow the "Http URL" method (https://webmin.com/docs/modules/webmin-configuration/#installing) and use the latest release package using [https://github.com/dave-lang/webmin-docker/releases/latest/download/docker.wbm.gz](https://github.com/dave-lang/webmin-docker/releases/latest/download/docker.wbm.gz). Alternatively you can download and install it directly from the [releases page](https://github.com/dave-lang/webmin-docker/releases) or it build manually, the packaging steps are in the GitHub action in the repo. -Once installed a new option 'Docker Containers' will appear in the menu under 'Servers'. +Once installed: +- 'View docker containers' will appear in the menu under 'Servers' + - If you are using an alternative context for Docker, set this under the module configuration link in the top left of "View docker containers" +- 'Docker Up' & 'Docker Container Up' will appear in the monitors that can be configured under 'Tools' > 'System and server status' ## Rootless Docker @@ -36,16 +42,23 @@ Experimental rootless docker support has been added via [docker contexts](https: ## Functionality -### Container listing/actions -image +**Container listing/actions** + +Screenshot showing container listing + +**Container inspection and logs** + +Screenshot showing container info + +Screenshot showing container logs + +**Host docker information** -### Container inspection and logs -image +Screenshot showing docker info display -image +**Monitors** -### Host docker information -image +Screenshot showing monitor support options ## Contributing @@ -59,7 +72,7 @@ The development environment creates 2 containers: - webmin_master - Webmin on focal ubuntu with docker & webmin auto start, available on port 10000 on the host - docker_dd - DIND container with rootless docker and webmin, available on port 20000 on the host (DOES NOT AUTO START). Very hacky. -### To use +### Setup 1. `cd tools` 1. `docker-compose up -d` to run docker compose as daemon 1. Open http://localhost:10000 to access the webmin console for docker on Ubuntu @@ -98,4 +111,4 @@ To start a test container 1. `cd /home/dind` 2. `docker-compose --context rootless up -d` -Use `docker exec -it docker_dd /bin/sh` to get a console. \ No newline at end of file +Use `docker exec -it docker_dd /bin/sh` to get a console. diff --git a/docker/container.cgi b/docker/container.cgi index c5054fd..962d265 100644 --- a/docker/container.cgi +++ b/docker/container.cgi @@ -11,14 +11,14 @@ our (%in); my $container = $in{'container'}; my $tab = $in{'tab'}; -my ($code, $container_name) = get_container_attr($container, 'Name'); +my ($code, $result) = get_container_attr($container, 'Name'); if ($code) { # Bad container id ui_print_header(undef, text('view_container_title', "not found"), "", undef, undef, $in{'nonavlinks'}); - &ui_print_endpage(ui_alert_box($code, 'danger'), "Back", "/"); + &ui_print_endpage(ui_alert_box($result, 'danger'), "Back", "/"); } # Trim leading / -$container_name = substr $container_name, 1; +my $container_name = substr($result, 1); ui_print_header(undef, text('view_container_title', $container_name), "", undef, undef, $in{'nonavlinks'}); my @tabs = ( [ 'log', &text('tab_log') ], diff --git a/docker/docker-lib.pl b/docker/docker-lib.pl index b3e01d8..a1d35cd 100644 --- a/docker/docker-lib.pl +++ b/docker/docker-lib.pl @@ -11,11 +11,20 @@ init_config(); -sub docker_command { +sub get_context { our (%config); + my $context = ""; + + if ($config{'docker_context'}) { + $context = ' --context "' . $config{'docker_context'} . '"'; + } + + return $context; +} + +sub docker_command { my($command, $format, $safe) = @_; $format ||= ""; - my $context = ""; $safe ||= 1; if ($format) { @@ -23,14 +32,16 @@ sub docker_command { } # If there's a context set, use it - if ($config{'docker_context'}) { - $context = ' --context "' . $config{'docker_context'} . '"'; - } + my $context = &get_context(); my ($result, $fail); my $code = execute_command('docker' . $context . ' ' . $command . $format, undef, \$result, \$fail, 0, $safe); if ($code != 0) { + my $trimEnd = index($fail, "errors pretty printing info"); + if ($trimEnd > 0) { + $fail = substr($fail, 0, $trimEnd); + } return $code, $fail; } @@ -41,7 +52,7 @@ sub docker_command { sub get_status { my ($code, $result) = docker_command('info'); if ($code != 0) { - return $result; + return $code, $result; } # my $json = decode_json($result); @@ -78,12 +89,7 @@ sub get_container_attr { my($container, $attr) = @_; my ($code, $result) = docker_command('inspect --type=container ' . $container, '{{.' . $attr . '}}'); - if ($code != 0) { - print "Bang"; - return $result; - } - - return 0, $result; + return $code, $result; } sub get_stats diff --git a/docker/index.cgi b/docker/index.cgi index e0ed8f2..0a17234 100644 --- a/docker/index.cgi +++ b/docker/index.cgi @@ -1,4 +1,5 @@ #!/usr/bin/perl +$trust_unknown_referers = 1; use strict; use warnings; use Data::Dumper; @@ -27,11 +28,12 @@ print ui_tabs_start(\@tabs, 'info', 'containers', 1); print ui_tabs_start_tab('mode', 'info'); my($status_fail, $status) = get_status(); if ($status_fail) { - print ui_alert_box($status_fail, 'danger'); + print ui_alert_box($status, 'danger'); } else { #print circular_grid($status); # Ugly recursive output print "
" . html_escape($status) . "
"; } + print ui_tabs_end_tab('mode', 'info'); # CONTAINERS TAB @@ -46,6 +48,10 @@ if ($fail) { print &ui_submit(text('label_refresh')); print &ui_form_end(),"
\n"; + if (scalar(@containers) == 0) { + print "No containers defined"; + } else { + # Provide some basic responsive support across all themes print '