37 lines
1.1 KiB
Plaintext

#!/bin/bash
###################################
############ by Sthope ############
###################################
#### USAGE
# bash -c "$(wget -qLO - https://git.sthope.dev/sthope/sthope-examples/raw/branch/master/docker_portainer_stacks/portainer/setup-dockerapi-notls)"
#
findRandomTcpPort(){
port=$(( 100+( $(od -An -N2 -i /dev/random) )%(1023+1) ))
while :
do
(echo >/dev/tcp/localhost/$port) &>/dev/null && port=$(( 100+( $(od -An -N2 -i /dev/random) )%(1023+1) )) || break
done
echo "$port"
}
mkdir -p /etc/systemd/system/docker.service.d/
p=$(findRandomTcpPort)
cat << EOF > /etc/systemd/system/docker.service.d/startup_options.conf
# /etc/systemd/system/docker.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:$p
EOF
systemctl daemon-reload;systemctl restart docker.service;clear
echo "######################################################################"
echo "############################# by Sthope ##############################"
echo "######################################################################"
echo "You can now connect Portainer to this host at port: $p"