Created
June 12, 2020 16:20
-
-
Save jsjohnst/b687372f66c6daf24ed5037d996e5788 to your computer and use it in GitHub Desktop.
Docker for Mac has a default TCP idle timeout of 300 seconds. This script helps disable/restore that as needed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
opmode=$1 | |
if [[ "x$opmode" == "x" ]]; then | |
echo "Usage:" | |
echo " ${0} <opmode>" | |
echo "Where <opmode> is either 'patch' or 'revert'" | |
exit 0; | |
fi | |
path_to_jq=$(command -v jq) | |
if [[ ! -x "$path_to_jq" ]]; then | |
echo "Installing JQ from Homebrew..." | |
brew install jq | |
fi | |
if [ "$opmode" == "patch" ]; then | |
if [[ -f "${HOME}/.docker-settings-json-backup" ]] ; then | |
echo "Backup exists, did you mean to revert?" | |
exit 1; | |
fi | |
if [[ -f "${HOME}/Library/Group Containers/group.com.docker/settings.json" ]]; then | |
echo "Backing up your existing docker settings.json to ${HOME}/.docker-settings-json-backup ..." | |
cp "${HOME}/Library/Group Containers/group.com.docker/settings.json" "${HOME}/.docker-settings-json-backup" | |
echo "Patching docker's settings.json to set vpnKitMaxPortIdleTime=0 ..." | |
jq .vpnKitMaxPortIdleTime=0 "${HOME}/Library/Group Containers/group.com.docker/settings.json" > "${TMPDIR}/patched-docker-settings.json" | |
mv "${TMPDIR}/patched-docker-settings.json" "${HOME}/Library/Group Containers/group.com.docker/settings.json" | |
echo "Success! -- now restart Docker" | |
exit 0; | |
else | |
echo "Couldn't find docker's settings.json in the expected location: ~/Library/Group Containers/group.com.docker/settings.json" | |
exit 2; | |
fi | |
fi | |
if [ "$opmode" == "revert" ]; then | |
if [[ ! -f "${HOME}/.docker-settings-json-backup" ]] ; then | |
echo "Backup doesn't exist, did you mean to patch?" | |
exit 1; | |
fi | |
if [[ -f "${HOME}/Library/Group Containers/group.com.docker/settings.json" ]]; then | |
echo "Restoring the original docker settings.json from backup ..." | |
mv "${HOME}/.docker-settings-json-backup" "${HOME}/Library/Group Containers/group.com.docker/settings.json" | |
echo "Success! -- now restart Docker" | |
exit 0; | |
else | |
echo "Couldn't find docker's settings.json in the expected location: ~/Library/Group Containers/group.com.docker/settings.json" | |
exit 2; | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment