阿里云docker相关介绍:https://cr.console.aliyun.com/?spm=a2c4g.11186623.2.3.MVsyD4#/accelerator
使用加速器可以提升获取Docker官方镜像的速度,加速器地址: https://yk9crw49.mirror.aliyuncs.com
本文转自 手把手 ,原文地址:https://www.shoubashou.com/app/docker/2018/1011/74.html
1. 安装/升级Docker客户端
对于Windows 10以下的用户,推荐使用Docker Toolbox
Windows安装文件:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/
对于Windows 10以上的用户 推荐使用Docker for Windows
Windows安装文件:http://mirrors.aliyun.com/docker-toolbox/windows/docker-for-windows/
2. 配置镜像加速器
针对安装了Docker Toolbox的用户,您可以参考以下配置步骤:
创建一台安装有Docker环境的Linux虚拟机,指定机器名称为default,同时配置Docker加速器地址。
docker-machine create --engine-registry-mirror=https://yk9crw49.mirror.aliyuncs.com -d virtualbox default
查看机器的环境配置,并配置到本地,并通过Docker客户端访问Docker服务。
docker-machine env default
eval "$(docker-machine env default)"
docker info
针对安装了Docker for Windows的用户,您可以参考以下配置步骤:
在系统右下角托盘图标内右键菜单选择 Settings,打开配置窗口后左侧导航菜单选择 Docker Daemon。编辑窗口内的JSON串,填写下方加速器地址:
{
"registry-mirrors": ["https://yk9crw49.mirror.aliyuncs.com"]
}
编辑完成后点击 Apply 保存按钮,等待Docker重启并应用配置的镜像加速器。
注意
Docker for Windows 和 Docker Toolbox互不兼容,如果同时安装两者的话,需要使用hyperv的参数启动。
docker-machine create --engine-registry-mirror=https://yk9crw49.mirror.aliyuncs.com -d hyperv default
Docker for Windows 有两种运行模式,一种运行Windows相关容器,一种运行传统的Linux容器。同一时间只能选择一种模式运行。
3. 相关文档
Docker 命令参考文档 https://docs.docker.com/engine/reference/commandline/cli/?spm=5176.8351553.0.0.4a8c1991Ncry1l
Dockerfile 镜像构建参考文档 https://docs.docker.com/engine/reference/builder/?spm=5176.8351553.0.0.4a8c1991Ncry1l
4. 下载镜像、创建容器
PS C:UsersAdministrator> docker pull centos:latest # 下载centos镜像最新版
latest: Pulling from library/centos
aeb7866da422: Pull complete
Digest: sha256:67dad89757a55bfdfabec8abd0e22f8c7c12a1856514726470228063ed86593b
Status: Downloaded newer image for centos:latest
PS C:UsersAdministrator> docker images # 查看镜像信息
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 75835a67d134 33 hours ago 200 MB
hello-world latest 4ab4c602aa5e 4 weeks ago 1.84 kB
PS C:UsersAdministrator> d:
PS D:> docker run -p 10022:22 -p 13306:3306 --privileged --name centos -it -v /d/scrapy:/shared mycms5/scrapy:1.0 /bin/bash
进入容器:
C:UsersAdministrator>docker exec -it centos /bin/bash 进入容器
[root@7789b2d68059 /]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@7789b2d68059 /]# passwd root
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@7789b2d68059 ~]# yum install net-tools #安装ifconfig
[root@7789b2d68059 /]# yum install vim
[root@7789b2d68059 /]# yum install openssh-server
[root@7789b2d68059 /]# systemctl status/start sshd
[root@7789b2d68059 /]# systemctl enable sshd
yum install gcc libffi-devel openssl-devel libxml2 libxslt-devel libxml2-devel python-devel -y
yum install python-setuptools
easy_install pip
easy_install lxml
pip install scrapy
# 将容器7789b2d68059保存为新的镜像,并添加提交人信息和说明信息
C:UsersAdministrator> docker commit -a "YuAN,912616.com" -m "centos7,scrapy" 7789b2d68059 scrapy:1.0
5. 镜像推送到阿里云
5.1 登录阿里云Docker Registry
$ sudo docker login --username=undefault@aliyun.com registry.cn-hangzhou.aliyuncs.com
用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。
5.2 从Registry中拉取镜像
$ sudo docker pull registry.cn-hangzhou.aliyuncs.com/mycms5/yuanr:[镜像版本号]
5.3 将镜像推送到Registry
$ sudo docker login --username=undefault@aliyun.com registry.cn-hangzhou.aliyuncs.com
$ sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/mycms5/yuanr:[镜像版本号]
$ sudo docker push registry.cn-hangzhou.aliyuncs.com/mycms5/yuanr:[镜像版本号]
请根据实际镜像信息替换示例中的[ImageId]和[镜像版本号]参数。
5.4 选择合适的镜像仓库地址
从ECS推送镜像时,可以选择使用镜像仓库内网地址。推送速度将得到提升并且将不会损耗您的公网流量。
如果您使用的机器位于经典网络,请使用 registry-internal.cn-hangzhou.aliyuncs.com 作为Registry的域名登录,并作为镜像命名空间前缀。
如果您使用的机器位于VPC网络,请使用 registry-vpc.cn-hangzhou.aliyuncs.com 作为Registry的域名登录,并作为镜像命名空间前缀。
5.5 示例
使用"docker tag"命令重命名镜像,并将它通过专有网络地址推送至Registry。
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry.aliyuncs.com/acs/agent 0.7-dfb6816 37bb9c63c8b2 7 days ago 37.89 MB
$ sudo docker tag 37bb9c63c8b2 registry-vpc.cn-hangzhou.aliyuncs.com/acs/agent:0.7-dfb6816
使用"docker images"命令找到镜像,将该镜像名称中的域名部分变更为Registry专有网络地址。
$ sudo docker push registry-vpc.cn-hangzhou.aliyuncs.com/acs/agent:0.7-dfb6816