Last active
January 29, 2020 08:26
-
-
Save wzulfikar/e7740906110beaa90216f8f37320f5d8 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# create docker engine config at /etc/docker/daemon.json | |
# to limit the size of container logs. | |
# usage (with curl): | |
# curl -s https://gist.githubusercontent.com/wzulfikar/e7740906110beaa90216f8f37320f5d8/raw/docker-daemon-log-opts.sh | sh | |
config_dir="/etc/docker" | |
config_file="$config_dir/daemon.json" | |
max_size=50m | |
IFS='' | |
config='{ | |
"log-opts": { | |
"max-size": "'$max_size'", | |
"max-file": "1" | |
} | |
}' | |
echo "creating config at ${config_file}.." | |
if [ -f "$config_file" ]; then | |
echo "[ABORTED] docker daemon config already exists." | |
echo "" | |
echo "you can manually add below 'log-opts' to your '$config_file':" | |
echo "$config" | |
exit | |
fi | |
if [ ! -d "$config_dir" ]; then | |
echo "[ERROR] cannot find config dir at '$config_dir'." | |
echo "" | |
echo "are you sure that docker is running in this host?" | |
exit | |
fi | |
# check if user has write permission | |
if [ ! -w "$config_dir" ]; then | |
echo "[ERROR] config dir is not writeable." | |
echo "" | |
echo "please make sure that you've write permission at '$config_dir'." | |
exit | |
fi | |
# write config to config file | |
echo $config > $config_file | |
echo "[DONE] finished writing docker daemon config for log-opts." | |
echo "size of container logs will be limited to $max_size." | |
echo "" | |
echo "you'll need to restart docker service to load the config." | |
echo 'ie. `service docker restart` (for ubuntu)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment