docker-compose之apt-mirror搭建局域网的源镜像

1. 概览

  • 系统:Ubuntu16.04
  • docker版本:Docker version 17.09.1-ce
  • docker-compose版本:docker-compose version 1.27.3

2. 介绍

这是一个Perl 开发的工具,用来从一个公开仓库中下载并镜像全部内容。这样就会包含公共仓库中所有的内容,其中自然也会包含你不需要的包。

基本架构:apt-mirror + nginx

占用存储空间:130G左右

3. 部署

  • apt-mirror Dockfile
FROM ubuntu:xenial-20180123

RUN apt update && \
    apt install -y cron apt-mirror && \
    apt autoremove -y && apt clean && rm -rf /var/lib/apt/lists* /tmp/* /var/tmp/* 

RUN echo "0 4 * * * root /usr/bin/apt-mirror > /var/spool/apt-mirror/cron.log" >> /etc/cron.d/apt-mirror

VOLUME ["/var/spool/apt-mirror"]

CMD ["cron", "-f"]

 

  • docker-compose.yml
version: '3'
services:
  local-mirror:
    image: local-mirror:v1.0
    restart: always
    volumes:
     - ./data:/data
     - ./apt.conf.d/mirror.list:/etc/apt/mirror.list
  mirror-nginx:
    image: nginx
    restart: always
    volumes:
     - ./data:/data
     - ./conf.d:/etc/nginx/conf.d
    ports:
     - 80:80

 

  • mirror.list
####### config ##################
#
# 配置数据基目录
set base_path     /data

# 配置镜像存储位置
# set mirror_path  $base_path/mirror
# 配置临时下载索引位置
# set skel_path    $base_path/skel
# 配置日子,URLs和MD5校验信息存储位置
# set var_path     $base_path/var

# 配置删除过期源脚本位置(默认不删除,方便安装旧版本软件)
# set cleanscript $var_path/clean.sh
# 设置默认架构, 可填: amd64 或 i386,默认是和本机一个架构
# set defaultarch  <running host architecture>
# 
# 设定下载后运行的脚本位置
# set postmirror_script $var_path/postmirror.sh
# 设置是否执行 下载后的脚本操作,默认是1(但是默认没有postmirror.sh脚本)
set run_postmirror 0

# 设置下载线程数
set nthreads     20
# 是否替换URL中的波浪线,替换成%7E(HTML代码),否则会跳过不进行下载
set _tilde 0
#
############# end config #############
# Ali yun(这里没有添加deb-src的源)
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
clean http://mirrors.aliyun.com/ubuntu

 

  • nginx default.conf
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /data/mirror;
        index  index.html index.htm;
        autoindex on;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

 

4. 启动

  • 进入local-mirror容器执行命令进行源拉取
nohup /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log &
  • 拉取路径

/data

5. 客户端配置

  • 修改source.lst
kyfq@mirro:/home/hdd0/mirror-docker/conf.d$ cat /etc/apt/sources.list
deb [arch=amd64] http://192.168.2.77/mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb [arch=amd64] http://192.168.2.77/mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb [arch=amd64] http://192.168.2.77/mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse  
deb [arch=amd64] http://192.168.2.77/mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb [arch=amd64] http://192.168.2.77/mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

 

  • 更新源
sudo apt-get update

 

  • 安装软件

 

 

 

版权声明:
作者:lee
链接:https://www.goufusheng.top/archives/732
来源:苟浮生的桃花扇
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录