firewall for Docker

This commit is contained in:
Darren 2023-09-28 18:52:35 +08:00 committed by GitHub
parent 6b9a448463
commit 4fc0732fc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -194,7 +194,7 @@ install_backends() {
fi
container_names=$(docker ps -a --format "{{.Names}}" --filter "name=websoft9")
sudo docker compose down
sudo docker compose -p websoft9 down
# delete some dead containers that docker compose cannot deleted
if [ ! -z "$container_names" ]; then

View file

@ -113,6 +113,22 @@ fi
}
Set_Firewall(){
echo "$echo_prefix_cockpit Set Firewalld for Docker"
if command -v firewall-cmd &> /dev/null; then
if ! systemctl is-active --quiet firewalld; then
sudo systemctl start firewalld
sudo firewall-cmd --zone=trusted --remove-interface=docker0 --permanent
sudo firewall-cmd --reload
sudo systemctl stop firewalld
else
sudo firewall-cmd --zone=trusted --remove-interface=docker0 --permanent
sudo firewall-cmd --reload
fi
fi
}
Set_Docker(){
# should have Docker server and Docker cli
if docker_exist; then
@ -121,6 +137,7 @@ if docker_exist; then
sudo systemctl restart docker
if ! docker network inspect websoft9 > /dev/null 2>&1; then
sudo docker network create websoft9
sudo systemctl restart docker
fi
else
echo "Docker settings failed, exit..."
@ -129,4 +146,5 @@ fi
}
Upgrade_Docker
Set_Firewall
Set_Docker