项目作者: madharjan

项目描述 :
Docker container for Squid
高级语言: Shell
项目地址: git://github.com/madharjan/docker-squid.git
创建时间: 2017-02-28T16:46:05Z
项目社区:https://github.com/madharjan/docker-squid

开源协议:MIT License

下载


docker-squid

Build Status
Layers

Docker container for Squid Proxy based on madharjan/docker-base

Squid configuration and Transparent Proxy configuration based on jpetazzo/squid-in-a-can

Changes

  • Squid and iptables in single container
  • Install iptables config if run as Transparent Proxy and cleanup iptables config on container stop

Features

  • Environment variables to set upstream proxy & authentication
  • Environment variables to set cache settings
  • Bats (sstephenson/bats) based test cases

Usages

  • Run docker-squid as Transparent Proxy while docker build to speedup build time by caching OS packages downloads
  • Run docker-squid as Transparent Proxy while docker build behind Corporate Proxy WITHOUT changing Dockerfile (works only if all downloads from Internet is HTTP only, NOT HTTPS)
  • Run docker-squid to conserve bandwidth on slow Internet connection by caching frequently downloaded files

Squid 3.3.8 (docker-squid)

Environment

Variable Default Example
DISABLE_SQUID 0 1 (to disable)
SQUID_INTERFACE_IP 0.0.0.0 170.17.42.1
SQUID_HTTP_PORT 3128 8080
SQUID_INTERCEPT_PORT 3129 8081
SQUID_MAXIMUM_OBJECT_SIZE 1024 512 (MB)
SQUID_DISK_CACHE_SIZE 10000 1000
SQUID_CACHE_PEER_HOST proxyHost
SQUID_CACHE_PEER_PORT proxyPort
SQUID_CACHE_PEER_AUTH user:pass
ENABLE_TRANSPARENT_PROXY 0 1 (to enable)

Build

  1. # clone project
  2. git clone https://github.com/madharjan/docker-squid
  3. cd docker-squid
  4. # build
  5. make
  6. # tests
  7. make run
  8. make test
  9. # clean
  10. make clean

Run

Note: update environment variables below as necessary

  1. # prepare foldor on host for container volumes
  2. sudo mkdir -p /opt/docker/squid/cache/
  3. sudo mkdir -p /opt/docker/squid/log/
  4. # stop & remove previous instances
  5. docker stop squid
  6. docker rm squid
  7. # run container
  8. docker run -d \
  9. -p 8080:3128 \
  10. -e SQUID_CACHE_PEER_HOST=[ProxyHost] \
  11. -e SQUID_CACHE_PEER_PORT=[ProxyPort] \
  12. -v /opt/docker/squid/cache:/var/cache/squid \
  13. -v /opt/docker/squid/log:/var/log/squid \
  14. --name squid \
  15. madharjan/docker-squid:3.5.12
  16. # run container as transparent proxy
  17. docker run -d \
  18. --network=host \
  19. --cap-add=NET_ADMIN \
  20. -e SQUID_HTTP_PORT=9090 \
  21. -e SQUID_INTERCEPT_PORT=9091 \
  22. -e SQUID_CACHE_PEER_HOST=proxyHost \
  23. -e SQUID_CACHE_PEER_PORT=proxyPort \
  24. -e ENABLE_TRANSPARENT_PROXY=1 \
  25. -v /opt/docker/squid/cache:/var/cache/squid \
  26. -v /opt/docker/squid/log:/var/log/squid \
  27. --name squid_t \
  28. madharjan/docker-squid:3.5.12

Systemd Unit File

Note: update environment variables below as necessary

  1. [Unit]
  2. Description=Squid
  3. After=docker.service
  4. [Service]
  5. TimeoutStartSec=0
  6. ExecStartPre=-/bin/mkdir -p /opt/docker/squid/cache
  7. ExecStartPre=-/bin/mkdir -p /opt/docker/squid/log
  8. ExecStartPre=-/usr/bin/docker stop squid
  9. ExecStartPre=-/usr/bin/docker rm squid
  10. ExecStartPre=-/usr/bin/docker pull madharjan/docker-squid:3.5.12
  11. ExecStart=/usr/bin/docker run \
  12. -p 8080:3128 \
  13. -v /opt/docker/squid/cache:/var/cache/squid \
  14. -v /opt/docker/squid/log:/var/log/squid \
  15. --name squid \
  16. madharjan/docker-squid:3.5.12
  17. ExecStop=/usr/bin/docker stop -t 2 squid
  18. [Install]
  19. WantedBy=multi-user.target

Generate Systemd Unit File

Variable Default Example
PORT 3128
VOLUME_HOME /opt/docker /opt/data
SQUID_CACHE_PEER_HOST proxy.domain.com
SQUID_CACHE_PEER_PORT 8080
  1. # generate template.service
  2. docker run --rm \
  3. -e PORT=3128 \
  4. -e VOLUME_HOME=/opt/docker \
  5. -e VERSION=3.5.12 \
  6. -e SQUID_CACHE_PEER_HOST=proxy.domain.com \
  7. -e SQUID_CACHE_PEER_PORT=8080 \
  8. madharjan/docker-squid:3.5.12 \
  9. template-systemd-unit | \
  10. sudo tee /etc/systemd/system/template.service
  11. sudo systemctl enable template
  12. sudo systemctl start template