安装docker
docker_install.sh
#!/bin/bash
base_path=$(
cd "$(dirname "$0")" || exit 1
pwd
)
function download_jq() {
wget "https://github.com/jqlang/jq/releases/download/${jq_tag}/jq-linux-amd64" -P $base_path
}
function install_jq() {
cp jq-linux-amd64 /usr/local/bin/jq
chmod +x /usr/local/bin/jq
}
function download_docker() {
wget https://download.docker.com/linux/static/stable/x86_64/docker-${docker_version:1}.tgz -P $base_path
wget https://raw.githubusercontent.com/docker/cli/${docker_version}/contrib/completion/bash/docker -P $base_path
wget https://raw.githubusercontent.com/moby/moby/${docker_version}/contrib/init/systemd/docker.service -P $base_path
wget https://raw.githubusercontent.com/moby/moby/${docker_version}/contrib/init/systemd/docker.socket -P $base_path
}
function download_compose() {
wget https://github.com/docker/compose/releases/download/${compose_version}/docker-compose-`uname -s`-`uname -m` -P $base_path
}
function install_docker() {
# yum install bash-completion -y
mkdir -p /etc/docker
mkdir -p /etc/bash_completion.d
cp ${base_path}/docker /etc/bash_completion.d/docker
cp ${base_path}/docker.service /usr/lib/systemd/system/docker.service
cp ${base_path}/docker.socket /usr/lib/systemd/system/docker.socket
read -p "输入docker数据存储目录,直接回车则为默认值/var/lib/docker: " data_root
read -p "输入docker信任私有仓库,直接回车则默认值为127.0.0.1: " insecure_registries
cat > /etc/docker/daemon.json <<-EOF
{
"exec-opts":[
"native.cgroupdriver=systemd"
],
"insecure-registries":[
"${insecure_registries:-127.0.0.1}"
],
"max-concurrent-downloads":10,
"default-ulimits":{
"nofile":{
"Name":"nofile",
"Hard":65535,
"Soft":65535
}
},
"live-restore":true,
"log-driver":"json-file",
"log-level":"warn",
"log-opts":{
"max-size":"10m",
"max-file":"5"
},
"data-root":"${data_root:-/var/lib/docker}"
}
EOF
tar -zxvf ${base_path}/docker-${docker_version:1}.tgz -C /usr/bin/ --strip-components=1
groupadd docker
usermod -aG docker ${USER}
systemctl daemon-reload
systemctl enable --now docker.service
}
function install_compose() {
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
cp ${base_path}/docker-compose-`uname -s`-`uname -m` /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
}
function main() {
jq_tag="$(curl https://api.github.com/repos/jqlang/jq/releases/latest | grep ' "tag_name": ' | awk -F'"' '{print $4}')"
download_jq
install_jq
docker_version="$(curl --retry 5 -sSL https://api.github.com/repos/moby/moby/releases/latest | jq -r '.tag_name' || exit 1)"
compose_version="$(curl --retry 5 -sSL https://api.github.com/repos/docker/compose/releases/latest | jq -r '.tag_name' || exit 1)"
download_docker
download_compose
install_docker
install_compose
}
main $@