Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.