You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I appreciate this program, very handy! I'm also using WatchYourLan. These have both made a couple of my markdown files irrelevant, and that's a good thing!
I just want to share an issue I had with the docker-export.sh file. As it currently is, the only thing it produced for me is a file, /tmp/wyp-docker.txt, containing a list of all my docker container names. The information echoed to the command line was correct, but it didn't get saved to the file. I copied the list of container names to the hosts.yaml file, but it didn't seem to do anything for me.
It's also very possible I've misunderstood or done something wrong with the provided docker-export.sh file.
I'm sharing my modified version of the script that got me what I believe is the intended file.
This modified version outputs to a yaml file and cleans up the txt file. It has a done message, but doesn't output anything while executing. Even for my ~50 containers, run time is maybe a second or two, so it didn't seem necessary. My docker containers are on a Debian 12 host in case that's important. After I ran my modified version and did a scan, there were only two docker container ports it didn't catch.
Apologies if I messed up, misunderstood, or misread, something.
#!/usr/bin/env bash# This script generates a WatchYourPorts config from Docker containers.# HOW TO USE# 1. Run this script on a server, where Docker is installed:# ./docker-export.sh $ADDR# $ADDR is IP or domain name of the server, without http(s):// prefix# It will be used to ping ports# 2. Paste the output to hosts.yaml file in WYP config dir# 3. You can add as many servers to hosts.yaml, as you want
docker ps -a --format "{{.Names}}">/tmp/wyp-docker.txt
{
echo$1':'echo' name:'echo' addr: '$1echo' portmap:'whileread NAME;do
PORT=$(docker inspect $NAME| grep HostPort | sed '1!d;s/"HostPort": //;s/,//;s/"//g')if [ ${#PORT}-ge 1 ];thenecho''$PORT':'echo' name: '$NAMEecho' port: '$PORTecho' state: false'echo' watch: true'fidone</tmp/wyp-docker.txt
} > /tmp/wyp-docker-output.yaml
echo"Output has been saved to /tmp/wyp-docker-output.yaml"
rm /tmp/wyp-docker.txt
And thank you again for sharing this program!
The text was updated successfully, but these errors were encountered:
I decided to go another route, because I like to control prints, and I don't want to mess with multiple files.
#!/bin/bash# ## This script generates a WatchYourPorts config from Docker containers.## HOW TO USE# 1. Run this script on a server, where Docker is installed:# ./docker-export.sh $ADDR# $ADDR is IP or domain name of the server, without http(s):// prefix# It will be used to ping ports# 2. Paste the output to hosts.yaml file in WYP config dir# 3. You can add as many servers to hosts.yaml, as you want## If you get the error:# bash: ./ports_docker_import.sh: /bin/bash^M: bad interpreter: No such file or directory# Run the command:# sudo sed -i -e 's/\r$//' ports_docker_import.sh# ## ## Output File# #
file_output="$(pwd)/data/wyp/hosts.yaml"# ## Permissions# #
sudo touch $file_output
sudo chmod 0644 $file_output# ## Docker Container List# #
CONTAINERS=$(docker ps -a --format "{{.Names}}")# ## Build Host Config# #echo"$1:"| tee $file_outputecho" name: $2"| tee -a $file_outputecho" addr: $1"| tee -a $file_outputecho" portmap:"| tee -a $file_output# ## Iterate docker container names# #while IFS= read -r id;do
PORT=`docker inspect $id| grep HostPort | sed '1!d;s/"HostPort": //;s/,//;s/"//g'| tr -d '[:space:]'`if [ ${#PORT}-ge 1 ];thenecho"$PORT:"| tee -a $file_outputecho" name: $id"| tee -a $file_outputecho" port: $PORT"| tee -a $file_outputecho" state: false"| tee -a $file_outputecho" watch: true"| tee -a $file_outputfidone<<<"$CONTAINERS"
Also supports the name of the host
./ports_docker_import.sh xx.xx.xx.xx domain.com
But yeah, it wasn't just you @JSouthGB -- I was also just getting a list of container names. Nothing else.
I appreciate this program, very handy! I'm also using WatchYourLan. These have both made a couple of my markdown files irrelevant, and that's a good thing!
I just want to share an issue I had with the
docker-export.sh
file. As it currently is, the only thing it produced for me is a file,/tmp/wyp-docker.txt
, containing a list of all my docker container names. The information echoed to the command line was correct, but it didn't get saved to the file. I copied the list of container names to thehosts.yaml
file, but it didn't seem to do anything for me.It's also very possible I've misunderstood or done something wrong with the provided
docker-export.sh
file.I'm sharing my modified version of the script that got me what I believe is the intended file.
This modified version outputs to a yaml file and cleans up the txt file. It has a done message, but doesn't output anything while executing. Even for my ~50 containers, run time is maybe a second or two, so it didn't seem necessary. My docker containers are on a Debian 12 host in case that's important. After I ran my modified version and did a scan, there were only two docker container ports it didn't catch.
Apologies if I messed up, misunderstood, or misread, something.
And thank you again for sharing this program!
The text was updated successfully, but these errors were encountered: