Captain's Geek-Island Captain's Geek-Island
首页
生活如斯乎
架构师的路
  • 分类
  • 标签
  • 归档
沉洋官网 (opens new window)

SleepyOcean

走,找新大陆去
首页
生活如斯乎
架构师的路
  • 分类
  • 标签
  • 归档
沉洋官网 (opens new window)
  • 计算机基础

  • 并发专题

  • 性能调优专题

  • 工具专题

  • 源码框架专题

  • 设计模式

  • 分布式专题

  • 实战专题

    • QA展板
    • ES高可用集群搭建
    • Mysql主备复制架构
    • docker搭建基础中间件
    • docker部署微服务
    • k8s集群搭建
    • dockerhub私有容器仓库搭建
      • 一、环境准备
      • 二、dockerhub搭建
        • 1. 搭建dockerhub容器
        • 2. 配置私有仓库地址
        • 3. 提交本地镜像到私有仓库
      • 三、拉取私有仓库镜像
        • 1. 配置私有仓库地址
        • 2. 拉取镜像
    • docker搭建sonarQube
    • docker搭建Confluence
    • docker搭建GitLab
    • Electron开发跨平台应用指南
    • Docker搭建ElasticSearch开发环境
    • Docker搭建Jenkins
    • Docker搭建ELK
    • Docker搭建nocas-server
    • Docker搭建各类Paas服务
  • 技术杂文

  • 云原生专题

  • 大数据分析专题

  • 前端专题

  • 运维专题

  • 经验专题

  • 面试专题

  • 软实力专题

  • 架构师的路
  • 实战专题
SleepyOcean
2020-08-21

DockerHub私有容器仓库搭建

在使用Docker Hub这样的公共仓库时经常会出现网络速度缓慢,申请注册麻烦等等令人头疼的问题。本文将会讲述如何在局域网通过docker搭建私有容器仓库。当然使用私有仓库主要有以下两个优点:

1、节省网络带宽,每个镜像不用每个人都去官网下载,只需要从私有仓库中下载即可。

2、提供镜像资源利用,针对公司内部使用的镜像,推送到本地的私有仓库,供公司内部的人员使用。

# 一、环境准备

两台装有docker(尽量保证docker的版本都一致)的Debian9.11(当然其他Linux也是一样的)的虚拟机

  • 虚拟机一:192.168.88.100 用作私有仓库
  • 虚拟机二:192.168.88.101 普通用户机

# 二、dockerhub搭建

192.168.88.100 私有仓库

# 1. 搭建dockerhub容器

#!/bin/bash

# 拉取 registry 镜像
docker pull registry

# 查看 registry 镜像是否拉取成功
docker images | grep registry

# 启动 registry 并将仓库数据映射到本地指定目录。
docker run -d -p 5000:5000 -v /docker/registry/:/var/lib/registry/ --name registry --restart=always registry

# 查看容器启动情况
docker ps
1
2
3
4
5
6
7
8
9
10
11
12
13

默认情况下,会将仓库放在容器内的/tmp/registry目录下,这样有个问题,如果容器被删除,则存放在容器中的镜像也会丢失。所以一般情况下建议指定本地一个目录挂载到容器内的/tmp/registry下(新版本是/var/lib/registry)

# 2. 配置私有仓库地址

# 在 /etc/docker/daemon.json 配置文件中添加 "insecure-registries": [ "192.168.88.100:5000"] 此处IP为私有仓库IP
$ cat /etc/docker/daemon.json 
{
"registry-mirrors": ["https://eoxejquzx.mirror.aliyuncs.com"],
"insecure-registries": [ "192.168.88.100:5000"]
}

# 修改完成后重启docker服务
$ systemctl restart docker
1
2
3
4
5
6
7
8
9

# 3. 提交本地镜像到私有仓库

docker commit :从容器创建一个新的镜像。

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
1

-a :提交的镜像作者;

-c :使用Dockerfile指令来创建镜像;

-m :提交时的说明文字;

-p :在commit时,将容器暂停。

# 提交本地容器生成镜像
$ docker commit -a "sleepyocean" -m "custom-hello-container" hello-test-container 192.168.88.100:5000/cust-hello:v1.0

# 查看镜像列表
$ docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
192.168.88.100:5000/cust-hello   v1.0                403e0f82a578        4 seconds ago       26.2MB
registry                         latest              2d4f4b5309b1        2 months ago        26.2MB
hello-world                      latest              bf756fb1ae65        7 months ago        13.3kB

# 推送镜像到私有仓库
$ docker push 192.168.88.100:5000/cust-hello:v1.0
The push refers to repository [192.168.88.100:5000/cust-hello]
0d635023c749: Pushed 
b3f4654534d1: Pushed 
a5f34560cdd9: Pushed 
2393466513b5: Pushed 
f5b92gte0e42: Pushed 
3e789b409db3: Pushed 
v1.0: digest: sha256:881141c72bbf0e0f848239cf97266e5865632467b78f0a46b943bf5b9324991f size: 1570
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# 三、拉取私有仓库镜像

192.168.88.101 普通用户机

# 1. 配置私有仓库地址

# 在 /etc/docker/daemon.json 配置文件中添加 "insecure-registries": [ "192.168.88.100:5000"] 此处IP为私有仓库IP
$ cat /etc/docker/daemon.json 
{
"registry-mirrors": ["https://eoxejquzx.mirror.aliyuncs.com"],
"insecure-registries": [ "192.168.88.100:5000"]
}

# 修改完成后重启docker服务
$ systemctl restart docker
1
2
3
4
5
6
7
8
9

# 2. 拉取镜像

# 拉取私有镜像
$ docker pull 192.168.88.100:5000/cust-hello:v1.0

# 查看拉取镜像
$ docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED                  SIZE
192.168.88.100:5000/cust-hello   v1.0                403e0f82a578        Less than a second ago   26.2MB
1
2
3
4
5
6
7
#dockerhub #私有容器仓库
上次更新: 2021/01/18, 09:01:00

← k8s集群搭建 docker搭建sonarQube →

新鲜出炉
01
记录 - 快速搭建自动化部署平台
04-13
02
Docker搭建各类Paas服务
03-01
03
系统配置 - Android TV配置
02-12
更多文章>
Copyright © 2019-2022 SleepyOcean | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式