Giter Site home page Giter Site logo

docker-squid's Introduction

Transparent HTTP Cacheing Container using Squid

This Dockerfile builds an Alpine Linux container using Squid configured to work in transparent mode as a small and fast caching web proxy.

Why?

If you build a lot of containers, you might be spending a lot of time waiting for packages to download. Using Squid to cache downloads automatically saves time and bandwidth and it is totally transparent to you.

Usage

This docker image is available as a trusted build on the docker index, so there's no setup required. Using this image for the first time will start a download. Further runs will be immediate, as the image will be cached locally.

The recommended way to run this container looks like this:

docker run -d --name squid --net host --privileged riddopic/squid

Next on your docker host you will need to setup an IPtables rule to transparently route all HTTP requests through the proxy running in the container:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 3129 -w

Inspecting the container

If you would like to have a look around or check the logs you can connect to the container using docker exec:

docker exec -it squid /bin/ash

Tuning

The container can be tuned using environment variables.

Variable Description
MAX_CACHE_OBJECT Squid has a maximum object cache size. Often when caching system packages vs standard web content it is valuable to increase this size. Use the -e MAX_CACHE_OBJECT=1024 to set the max object size (in MB).
DISK_CACHE_SIZE TT The squid disk cache size can be tuned. use -e DISK_CACHE_SIZE=5000 to set the disk cache size (in MB).
SQUID_DIRECTIVES_ONLY The contents of squid.conf will only be what's defined in SQUID_DIRECTIVES giving the user full control of squid.
SQUID_DIRECTIVES This will append any contents of the environment variable to squid.conf. It is expected that you will use multi-line block quote for the contents.

Persistent Cache

When the container is terminated the cache is lost. To prevent this and maintain a persistent cache you can use a mounted volume. The cache location is /var/cache/squid so if you mount that as a volume you can get persistent caching. Use -v /home/user/squid_cache:/var/cache/squid in your command line to enable persistent caching.

License

Author::   Stefano Harding <[email protected]>
Copyright: 2014-2015, Stefano Harding

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

docker-squid's People

Contributors

riddopic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.