Last active
September 11, 2024 01:48
-
-
Save koichirok/a1b20be426b3b08be6f3924402ec7901 to your computer and use it in GitHub Desktop.
generate tuned daemon.json
This file contains 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
#!/bin/sh | |
# | |
# This script generates a /etc/docker/daemon.json file tuned for the current environment. | |
# Currently, only the mtu option is suaported. | |
# | |
# Usefull for the developers who use Docker-in-Docker feature in their dev containers with VS Code and | |
# need to set the mtu option for the inner Docker daemon. | |
# | |
# This script is intended to be run using a DevContainer feature like script_runner. | |
# See https://github.com/wxw-matt/devcontainer-features for more details. | |
if ! command -v dockerd > /dev/null; then | |
echo "dockerd command not found. Please install Docker first." | |
exit 0 | |
fi | |
if [ -f /etc/docker/daemon.json ]; then | |
echo "File /etc/docker/daemon.json already exists. Exiting." | |
exit 0 | |
fi | |
generate_mtu_config() { | |
# find default route interface | |
default_route_interface="$(ip route show default | sed -e 's/^.*dev //' -e 's/ .*$//')" | |
[ -z "$default_route_interface" ] && return | |
eval "$(ip link show "$default_route_interface" | grep -o "mtu [0-9]\{1,\}" | tr ' ' '=')" | |
if [ "$mtu" ] && [ "$mtu" -ne 1500 ]; then | |
echo " \"mtu\": $mtu," | |
fi | |
} | |
if [ "$(id -u)" -ne 0 ]; then | |
sudo=sudo | |
fi | |
mkdir -p /etc/docker | |
{ | |
echo '{' | |
{ | |
generate_mtu_config | |
} | sed '$ s/,$//' | |
echo '}' | |
} | $sudo tee /etc/docker/daemon.json > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment