dotfiles/apps/docker.sh

51 lines
1.3 KiB
Bash
Raw Normal View History

2020-11-02 04:08:18 +00:00
#!/bin/sh
2020-09-18 04:16:15 +00:00
2020-11-02 04:08:18 +00:00
DIR=$(readlink -f "$(dirname "$0")")
. "$DIR/../env.sh"
2020-09-18 04:16:15 +00:00
# install docker
case "$PM" in
apt)
# snap docker will intefere native docker.io, must be dealt with
sudo snap remove --purge docker
2020-09-18 04:16:15 +00:00
sudo apt install -y docker.io docker-compose
2020-11-04 06:05:09 +00:00
! command -v pip3 && "$PDIR/python/install.sh"
2020-09-18 04:16:15 +00:00
sudo pip3 install docker-compose
;;
pacman)
2020-09-18 18:01:58 +00:00
sudo pacman -S --needed docker docker-compose
2020-09-18 04:16:15 +00:00
;;
esac
sudo systemctl enable docker
sudo systemctl start docker
2020-09-19 01:23:38 +00:00
2020-09-18 04:16:15 +00:00
# configuration
2020-11-02 04:08:18 +00:00
sudo usermod -aG docker "$USER"
2020-09-19 01:23:38 +00:00
2020-09-27 10:04:33 +00:00
# completion
case "$DEFAULT_SHELL" in
$FISH)
2020-11-02 04:08:18 +00:00
curl -sLo "$HOME/.config/fish/completions/docker.fish" --create-dirs \
2020-09-27 10:04:33 +00:00
'https://github.com/docker/cli/raw/master/contrib/completion/fish/docker.fish'
;;
esac
2020-09-22 04:16:06 +00:00
# set mirror
2020-11-02 04:08:18 +00:00
if in_china && [ -d /etc/docker ]; then
2020-09-19 01:23:38 +00:00
if [ -f /etc/docker/daemon.json ]; then
# backup
[ ! -f /etc/docker/daemon.bak.json ] && \
sudo cp /etc/docker/daemon.json /etc/docker/daemon.bak.json
# read
dj=$(cat /etc/docker/daemon.json)
fi
2020-11-02 04:08:18 +00:00
[ -z "$dj" ] && dj='{}'
2020-09-22 04:16:06 +00:00
echo $dj | jq '. + {"registry-mirrors": ["https://izuhlbap.mirror.aliyuncs.com"]}' | \
sudo tee /etc/docker/daemon.json
2020-09-19 01:23:38 +00:00
sudo systemctl restart docker
fi