添加阿里镜像加速器以及在docker中的镜像的上传和下载和docker账号的关联
这是转到阿里云
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
在centos中
针对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF’
{
“registry-mirrors”: [“https://kbnfl5z3.mirror.aliyuncs.com”]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
在mac中
添加完后然后再用docker拉取镜像,我们先会觉得下载速度快多了
接下来我们要做的是把刚刚拉去的镜像上传到hub.docker.com上(没有docker账号的注册去,一会儿要用到)
-
本地创建一个Dockerfile文件,让它在这个centos的基础上去输出一个hello-world
touch Dockerfile
vi Dockerfile -
现在通过docker build生成一个新的镜像,-t可以指定新镜像的名字 . 表示在当前目录下
docker build -t centos/hello-world . -
接下来可以docker images查看本地镜像
4.然后docker run执行这个镜像,这时候生成一个新容器,我们可以对这个容器进行操作。
docker run centos/hello-world echo ‘hello world’bash -
给镜像打标签
修改标签:docker tag IMAGEID(镜像id) REPOSITORY:TAG(仓库:标签)
6.push镜像
先登录docker.hub
docker login
然后push上传
命令格式
docker push /:
Push成功之后,可登录到hub.docker.com网站,查看一下刚才创建的仓库名称
最后给hub.docker.com和github做一个关联
这里我已经关联上了;(在这之前如果没有github账号,还是那句话:“注册去”)