echo "Configuring docker proxy ..."
if [ -f /etc/docker/daemon.json ]; then
if grep -q registry-mirrors /etc/docker/daemon.json; then
- sudo sed -Ei 's/("registry-mirrors".*\[)(.*)\]/\1\2, \"'"${DOCKER_PROXY_URL}"'\"\]/' /etc/docker/daemon.json
+ sudo sed -i "s|registry-mirrors.*|registry-mirrors\": [\"${DOCKER_PROXY_URL}\"] |" /etc/docker/daemon.json
else
- sudo sed -i 's/{/{\n "registry-mirrors": [\"'"${DOCKER_PROXY_URL}"'\"]",/' /etc/docker/daemon.json
+ sudo sed -i "s|{|{\n \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"],|" /etc/docker/daemon.json
fi
else
- sudo cat << EOF > /etc/docker/daemon.json
+ sudo bash -c "cat << EOF > /etc/docker/daemon.json
{
- "registry-mirrors": ["${DOCKER_PROXY_URL}"]
+ \"registry-mirrors\": [\"${DOCKER_PROXY_URL}\"]
}
-EOF
+EOF"
fi
- sudo systemctl daemon-reload
+ sudo systemctl daemon-reload
sudo service docker restart
echo "... restarted Docker service again"
fi