docker 国内镜像与 docker hub 镜像, docker-compose

目录

  • 1. docker 国内镜像与 docker hub 镜像, docker-compose
    • 1.1. 通过国内镜像安装 docker
      • 1.1.1. Debian
      • 1.1.2. RHEL
    • 1.2. 官方安装
      • 1.2.1. 安装
      • 1.2.2. 设置: 非 root 用户直接使用
      • 1.2.3. 设置: 服务开机启动
    • 1.3. docker hub 镜像
      • 1.3.1. Docker Hub 源使用帮助
    • 1.4. docker-compose

1. docker 国内镜像与 docker hub 镜像, docker-compose

1.1. 通过国内镜像安装 docker

国内安装指南: https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/

1.1.1. Debian

# 如果你过去安装过 docker, 先删掉: 
sudo apt-get remove docker docker-engine docker.io

# 首先安装依赖: 
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

# 信任 Docker 的 GPG 公钥: 
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

# 对于 amd64 架构的计算机, 添加软件仓库: 
sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
   $(lsb_release -cs) \
   stable"

# 如果你是树莓派或其它 ARM 架构计算机, 请运行: 
echo "deb [arch=armhf] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
     $(lsb_release -cs) stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list

# 最后安装
sudo apt-get update
sudo apt-get install docker-ce

1.1.2. RHEL

# 如果你之前安装过 docker, 请先删掉
sudo yum remove docker docker-common docker-selinux docker-engine

# 安装一些依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

# 根据你的发行版下载 repo 文件: CentOS/RHEL
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

# 把软件仓库地址替换为 TUNA:
sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

# 最后安装: 
sudo yum makecache fast
sudo yum install docker-ce

1.2. 官方安装

Install: Install Docker Engine on Ubuntu

More: Linux post-installation steps for Docker Engine

1.2.1. 安装

Ubuntu:

# Uninstall any such older versions before attempting to install a new version
sudo apt-get remove docker docker-engine docker.io containerd runc

# Update the apt package index and install packages to allow apt to use a repository over HTTPS
sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

# Add Docker’s official GPG key
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Use the following command to set up the repository
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update the apt package index
sudo apt-get update

# Install Docker Engine, containerd, and Docker Compose.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Verify that the Docker Engine installation is successful by running the hello-world image:
sudo docker run hello-world

1.2.2. 设置: 非 root 用户直接使用

sudo groupadd docker
sudo usermod -aG docker $USER
docker run hello-world

1.2.3. 设置: 服务开机启动

To automatically start Docker and containerd on boot for other Linux distributions using systemd, run the following commands:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

To stop this behavior, use disable instead.

sudo systemctl disable docker.service
sudo systemctl disable containerd.service

1.3. docker hub 镜像

访问连接: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

针对 Docker 客户端版本大于 1.10.0 的用户

您可以通过修改 daemon 配置文件 /etc/docker/daemon.json 来使用加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
{
        "registry-mirrors": [
                "http://hub-mirror.c.163.com",
                "https://registry.cn-hangzhou.aliyuncs.com",
                "https://xxx.mirror.aliyuncs.com",
                "https://docker.mirrors.ustc.edu.cn"
        ]
}

1.3.1. Docker Hub 源使用帮助

  • 对于使用 systemd 的系统 (Ubuntu 16.04+、Debian 8+、CentOS 7), 在配置文件 /etc/docker/daemon.json 中加入(如果没有则新建一个):
{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}

重新启动 dockerd:

sudo systemctl restart docker
  • 对于使用 upstart 的系统 (Ubuntu 14.04、Debian 7 Wheezy), 在配置文件 /etc/default/docker 中的 DOCKER_OPTS 中配置 Hub 地址:

在配置文件 /etc/default/docker 中的 DOCKER_OPTS 中配置 Hub 地址:

DOCKER_OPTS="--registry-mirror=https://docker.mirrors.ustc.edu.cn/"

重新启动服务:

sudo service docker restart

检查 Docker Hub 是否生效

在命令行执行 docker info, 如果从结果中看到了如下内容, 说明配置成功。

Registry Mirrors:
    https://docker.mirrors.ustc.edu.cn/

1.4. docker-compose

官方: https://docs.docker.com/compose/install/

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

你可能感兴趣的:(hub,mirror,docker-ce,compose,install)