Docker 镜像可以通过多种官方和第三方渠道下载,以下是主要途径和详细说明:
nginx
, mysql
, ubuntu
),标签带 [Official]
标识。docker pull
命令下载(默认从 Docker Hub 拉取)。示例命令:
docker pull nginx # 下载最新版 nginx
docker pull ubuntu:20.04 # 下载指定版本的 Ubuntu
Google Container Registry (GCR):
地址: https://gcr.io
常用于 Kubernetes 和 Google Cloud 相关镜像(如 gcr.io/google-containers/busybox
)。
Amazon ECR (Elastic Container Registry):
地址: https://aws.amazon.com/ecr/
需 AWS 账号登录,适用于 AWS 服务。
Red Hat Quay:
地址: https://quay.io
提供企业级镜像(如 CoreOS、OpenShift 相关镜像)。
GitHub Container Registry (GHCR):
地址: https://ghcr.io
与 GitHub 仓库集成的镜像托管服务。
示例命令:
docker pull gcr.io/google-containers/busybox
docker pull quay.io/coreos/etcd
由于网络原因,国内从 Docker Hub 拉取镜像可能较慢,可使用以下国内镜像加速服务:
- 阿里云镜像加速器:
- 地址: https://cr.console.aliyun.com
- 需注册账号,获取个人加速器地址(如 https://<你的ID>.mirror.aliyuncs.com
)。
华为云镜像仓库:
地址: https://console.huaweicloud.com/swr/
腾讯云镜像加速:
地址: https://cloud.tencent.com/document/product/457/9113
配置方法:
修改 Docker 配置文件(如 /etc/docker/daemon.json
),添加镜像加速地址:
{
"registry-mirrors": ["https://<你的ID>.mirror.aliyuncs.com"]
}
重启 Docker 服务生效:
sudo systemctl restart docker
docker-registry
或企业级工具(如 Harbor、Nexus)搭建私有仓库。
bash
docker run -d -p 5000:5000 --name registry registry:2
bash
docker tag my-image localhost:5000/my-image
docker push localhost:5000/my-image
docker pull localhost:5000/my-image
直接导入/导出镜像:
通过 docker save
和 docker load
操作镜像文件(适用于离线环境):
docker save nginx > nginx.tar
docker load < nginx.tar
通过 Dockerfile 构建镜像:
从代码仓库(如 GitHub)拉取 Dockerfile 自行构建:
git clone https://github.com/user/my-project
cd my-project
docker build -t my-image .
镜像安全:
docker scan
或工具 Clair、Trivy)。版本控制:
python:3.9
),避免使用 latest
标签。权限问题:
docker login
)。通过以上渠道,你可以根据需求灵活获取 Docker 镜像。如有进一步问题(如特定镜像下载或配置问题),欢迎补充说明!