Update 'docker_portainer_stacks/portainer/setup-dockerapi-notls'

This commit is contained in:
sthope 2021-09-02 21:36:04 +02:00
parent f8c677aded
commit 79de6df9f4

View File

@ -1,3 +1,4 @@
#!/bin/bash
###################################
############ by Sthope ############
@ -7,17 +8,30 @@
# 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:2376
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:$p
EOF
systemctl daemon-reload
# systemctl daemon-reload
systemctl restart docker.service
# systemctl restart docker.service
echo "You can now connect Portainer to this host at port: $p"
echo "You can now connect Portainer to this host."