Docker-镜像

镜像就是打包好的环境与应用

镜像分类: 操作系统、应用程序

仓库:用于存放镜像

官方镜像仓库:https://hub.docker.com/

一、镜像

1.常用命令

#1.查看本地镜像
docker images
#2.搜索镜像
docker search centos
#3.拉取镜像
docker pull busybox
#4.推送镜像
docker push 镜像名
#5.删除镜像
docker rmi imagename:tag
docker rmi imageid
#6.打tag
docker tag busybox:latest tigerup/test:v1

2.镜像加速器

阿里容器镜像服务 ACRhttps://cr.console.aliyun.com/cn-hangzhou/new

用于提高镜像下载速度

先注册然后,查看镜像加速器

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://*****.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

3.镜像导入导出

  • 导入
# Usage:  docker save [OPTIONS] IMAGE [IMAGE...]
# Save one or more images to a tar archive (streamed to STDOUT by default)
docker save busybox -o /tmp/busybox.tar.gz
  • 导出
# Usage:  docker load [OPTIONS]
# Load an image from a tar archive or STDIN
docker load -i /tmp/busybox.tar.gz
docker load < /tmp/busybox.tar.gz

二、镜像仓库

1.官方自建镜像仓库

https://hub.docker.com/

创建仓库

使用

#登录
docker login
#打tag
docker tag busybox:latest tigerup/test:v1
#上传
docker push tigerup/test:v1
#下载
docker pull tigerup/test:v1
#登出
docker logout

2.阿里云镜像仓库

https://www.aliyun.com/product/acr?spm=5176.12825654.1kquk9v2l.1.73752c4aN6wMJ5&aly_as=HGTPjLMa

https://cr.console.aliyun.com/cn-beijing/instances/repositories

创建仓库

使用

3.harbor

Harbor是VMware公司开源了企业级Registry项目, 可以快速搭建一个企业级的Docker registry服务.

harbor由python语言开发, 需要使用docker-compose工具进行启动

配置yum

# Epel 源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# Cenos 源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#Docerk阿里源
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

安装docker-ce

yum install docker-ce

安装docker-compose

安装方式一:

yum install python-devel python2-pip -y
pip install docker-compose -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

安装方式二:

下载地址:https://github.com/docker/compose/releases

安装Harbor

下载地址:https://github.com/goharbor/harbor/releases

#1.解压
tar -xvf harbor-offline-installer-v1.5.0.tgz  -C /usr/local/
#2.修改配置文件
cd /usr/local/harbor/
vim harbor.cfg
....
#将hostname改成harbor服务器的IP
hostname = 10.1.1.12
#admin用户的默认密码,
harbor_admin_password = Harbor12345    

#3.安装
./install.sh

测试

访问:http://10.1.1.12

创建项目

测试,客户端上传镜像

第一步:因为dockerhttps通讯,暂时先跳过,使用http通讯

配置"insecure-registries": ["harbor服务器IP"]

vim /etc/docker/daemon.json
{
    "registry-mirrors": ["https://42h8kzrh.mirror.aliyuncs.com"], 
    "insecure-registries": ["192.168.122.18"]
}

systemctl restart docker

下载项目

docker tag busybox:latest 10.1.1.12/test/busybox:v1
docker login 10.1.1.12
#上传,注意:需要先创建项目 test
docker push 10.1.1.12/test/busybox:v1
#下载
docker pull 10.1.1.12/test/busybox:v1
docker logout 192.168.122.18

4.镜像仓库对比

官方仓库:网络问题,慢

阿里:速度快,但是数据安全性不能保证

自建仓库:速度快,安全性好,但是成本高

Last modification:June 15th, 2020 at 10:24 pm