一键安装Docker并配置国内镜像源

常用Docker,Docker-compose一键安装脚本

安装 Docker(三选一)

使用官方源安装(国内直接访问较慢):

1curl -fsSL https://get.docker.com | bash

使用阿里源安装:

1curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

使用中国区 Azure 源安装:

1curl -fsSL https://get.docker.com | bash -s docker --mirror AzureChinaCloud

启动Docker服务

设置开机自启:

1systemctl enable docker

启动 Docker:

1systemctl start docker

一键安装最新版 Docker Compose:

1COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oP "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | sort --version-sort | tail -n 1`
2sh -c "curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"
3chmod +x /usr/local/bin/docker-compose

配置国内镜像源

此步骤可选,非必须,国外VPS服务器直接无视。

 1mkdir -p /etc/docker
 2tee /etc/docker/daemon.json <<-'EOF'
 3{
 4  "registry-mirrors": [
 5    "https://0b27f0a81a00f3560fbdc00ddd2f99e0.mirror.swr.myhuaweicloud.com",
 6    "https://ypzju6vq.mirror.aliyuncs.com",
 7    "https://registry.docker-cn.com",
 8    "http://hub-mirror.c.163.com",
 9    "https://docker.mirrors.ustc.edu.cn"
10  ]
11}
12EOF
13systemctl daemon-reload
14systemctl restart docker

版权

评论