├── .circleci └── config.yml ├── .dockerignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── VERSION ├── docker-compose.yml ├── entrypoint.sh └── kubernetes ├── pod.yml └── service.yml /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | working_directory: /workdir 5 | docker: 6 | - image: docker:18.03.0-ce-git 7 | environment: 8 | IMAGE_NAME: "sameersbn/squid" 9 | 10 | steps: 11 | - checkout 12 | 13 | - setup_remote_docker: 14 | version: 18.03.1-ce 15 | 16 | - run: 17 | name: Docker info 18 | command: | 19 | docker version 20 | docker info 21 | 22 | - restore_cache: 23 | keys: 24 | - cache-{{ .Branch }} 25 | paths: 26 | - /cache/layers.tar 27 | 28 | - run: 29 | name: Loading docker cache 30 | command: | 31 | if [[ -f /cache/layers.tar ]]; then 32 | docker load -i /cache/layers.tar 33 | fi 34 | 35 | - run: 36 | name: Build docker image 37 | command: | 38 | docker build --cache-from=${IMAGE_NAME} -t ${IMAGE_NAME} . 39 | 40 | - run: 41 | name: Generate docker build image cache 42 | command: | 43 | mkdir -p /cache 44 | docker save -o /cache/layers.tar ${IMAGE_NAME} 45 | 46 | - save_cache: 47 | key: cache-{{ .Branch }}-{{ epoch }} 48 | paths: 49 | - /cache/layers.tar 50 | 51 | workflows: 52 | version: 2 53 | build-and-test: 54 | jobs: 55 | - build: 56 | filters: 57 | branches: 58 | only: /.*/ 59 | tags: 60 | only: /.*/ 61 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | circle.yml 3 | LICENSE 4 | VERSION 5 | README.md 6 | Changelog.md 7 | Makefile 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic-20190612 2 | LABEL maintainer="sameer@damagehead.com" 3 | 4 | ENV SQUID_VERSION=3.5.27 \ 5 | SQUID_CACHE_DIR=/var/spool/squid \ 6 | SQUID_LOG_DIR=/var/log/squid \ 7 | SQUID_USER=proxy 8 | 9 | RUN apt-get update \ 10 | && DEBIAN_FRONTEND=noninteractive apt-get install -y squid=${SQUID_VERSION}* \ 11 | && rm -rf /var/lib/apt/lists/* 12 | 13 | COPY entrypoint.sh /sbin/entrypoint.sh 14 | RUN chmod 755 /sbin/entrypoint.sh 15 | 16 | EXPOSE 3128/tcp 17 | ENTRYPOINT ["/sbin/entrypoint.sh"] 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Sameer Naik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: build 2 | 3 | build: 4 | @docker build --tag=sameersbn/squid . 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Circle CI](https://circleci.com/gh/sameersbn/docker-squid.svg?style=shield)](https://circleci.com/gh/sameersbn/docker-squid) [![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/squid/status "Docker Repository on Quay.io")](https://quay.io/repository/sameersbn/squid) 2 | 3 | # sameersbn/squid:3.5.27-2 4 | 5 | - [Introduction](#introduction) 6 | - [Contributing](#contributing) 7 | - [Issues](#issues) 8 | - [Getting started](#getting-started) 9 | - [Installation](#installation) 10 | - [Quickstart](#quickstart) 11 | - [Command-line arguments](#command-line-arguments) 12 | - [Persistence](#persistence) 13 | - [Configuration](#configuration) 14 | - [Usage](#usage) 15 | - [Logs](#logs) 16 | - [Maintenance](#maintenance) 17 | - [Upgrading](#upgrading) 18 | - [Shell Access](#shell-access) 19 | 20 | # Introduction 21 | 22 | `Dockerfile` to create a [Docker](https://www.docker.com/) container image for [Squid proxy server](http://www.squid-cache.org/). 23 | 24 | Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. 25 | 26 | ## Contributing 27 | 28 | If you find this image useful here's how you can help: 29 | 30 | - Send a pull request with your awesome features and bug fixes 31 | - Help users resolve their [issues](../../issues?q=is%3Aopen+is%3Aissue). 32 | - Support the development of this image with a [donation](http://www.damagehead.com/donate/) 33 | 34 | ## Issues 35 | 36 | Before reporting your issue please try updating Docker to the latest version and check if it resolves the issue. Refer to the Docker [installation guide](https://docs.docker.com/installation) for instructions. 37 | 38 | SELinux users should try disabling SELinux using the command `setenforce 0` to see if it resolves the issue. 39 | 40 | If the above recommendations do not help then [report your issue](../../issues/new) along with the following information: 41 | 42 | - Output of the `docker version` and `docker info` commands 43 | - The `docker run` command or `docker-compose.yml` used to start the image. Mask out the sensitive bits. 44 | - Please state if you are using [Boot2Docker](http://www.boot2docker.io), [VirtualBox](https://www.virtualbox.org), etc. 45 | 46 | # Getting started 47 | 48 | ## Installation 49 | 50 | Automated builds of the image are available on [Dockerhub](https://hub.docker.com/r/sameersbn/squid) and is the recommended method of installation. 51 | 52 | > **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/squid) 53 | 54 | ```bash 55 | docker pull sameersbn/squid:3.5.27-2 56 | ``` 57 | 58 | Alternatively you can build the image yourself. 59 | 60 | ```bash 61 | docker build -t sameersbn/squid github.com/sameersbn/docker-squid 62 | ``` 63 | 64 | ## Quickstart 65 | 66 | Start Squid using: 67 | 68 | ```bash 69 | docker run --name squid -d --restart=always \ 70 | --publish 3128:3128 \ 71 | --volume /srv/docker/squid/cache:/var/spool/squid \ 72 | sameersbn/squid:3.5.27-2 73 | ``` 74 | 75 | *Alternatively, you can use the sample [docker-compose.yml](docker-compose.yml) file to start the container using [Docker Compose](https://docs.docker.com/compose/)* 76 | 77 | ## Command-line arguments 78 | 79 | You can customize the launch command of the Squid server by specifying arguments to `squid` on the `docker run` command. For example the following command prints the help menu of `squid` command: 80 | 81 | ```bash 82 | docker run --name squid -it --rm \ 83 | --publish 3128:3128 \ 84 | --volume /srv/docker/squid/cache:/var/spool/squid \ 85 | sameersbn/squid:3.5.27-2 -h 86 | ``` 87 | 88 | ## Persistence 89 | 90 | For the cache to preserve its state across container shutdown and startup you should mount a volume at `/var/spool/squid`. 91 | 92 | > *The [Quickstart](#quickstart) command already mounts a volume for persistence.* 93 | 94 | SELinux users should update the security context of the host mountpoint so that it plays nicely with Docker: 95 | 96 | ```bash 97 | mkdir -p /srv/docker/squid 98 | chcon -Rt svirt_sandbox_file_t /srv/docker/squid 99 | ``` 100 | 101 | ## Configuration 102 | 103 | Squid is a full featured caching proxy server and a large number of configuration parameters. To configure Squid as per your requirements mount your custom configuration at `/etc/squid/squid.conf`. 104 | 105 | ```bash 106 | docker run --name squid -d --restart=always \ 107 | --publish 3128:3128 \ 108 | --volume /path/to/squid.conf:/etc/squid/squid.conf \ 109 | --volume /srv/docker/squid/cache:/var/spool/squid \ 110 | sameersbn/squid:3.5.27-2 111 | ``` 112 | 113 | To reload the Squid configuration on a running instance you can send the `HUP` signal to the container. 114 | 115 | ```bash 116 | docker kill -s HUP squid 117 | ``` 118 | 119 | ## Usage 120 | 121 | Configure your web browser network/connection settings to use the proxy server which is available at `172.17.0.1:3128` 122 | 123 | If you are using Linux then you can also add the following lines to your `.bashrc` file allowing command line applications to use the proxy server for outgoing connections. 124 | 125 | ```bash 126 | export ftp_proxy=http://172.17.0.1:3128 127 | export http_proxy=http://172.17.0.1:3128 128 | export https_proxy=http://172.17.0.1:3128 129 | ``` 130 | 131 | To use Squid in your Docker containers add the following line to your `Dockerfile`. 132 | 133 | ```dockerfile 134 | ENV http_proxy=http://172.17.0.1:3128 \ 135 | https_proxy=http://172.17.0.1:3128 \ 136 | ftp_proxy=http://172.17.0.1:3128 137 | ``` 138 | 139 | ## Logs 140 | 141 | To access the Squid logs, located at `/var/log/squid/`, you can use `docker exec`. For example, if you want to tail the access logs: 142 | 143 | ```bash 144 | docker exec -it squid tail -f /var/log/squid/access.log 145 | ``` 146 | 147 | You can also mount a volume at `/var/log/squid/` so that the logs are directly accessible on the host. 148 | 149 | # Maintenance 150 | 151 | ## Upgrading 152 | 153 | To upgrade to newer releases: 154 | 155 | 1. Download the updated Docker image: 156 | 157 | ```bash 158 | docker pull sameersbn/squid:3.5.27-2 159 | ``` 160 | 161 | 2. Stop the currently running image: 162 | 163 | ```bash 164 | docker stop squid 165 | ``` 166 | 167 | 3. Remove the stopped container 168 | 169 | ```bash 170 | docker rm -v squid 171 | ``` 172 | 173 | 4. Start the updated image 174 | 175 | ```bash 176 | docker run -name squid -d \ 177 | [OPTIONS] \ 178 | sameersbn/squid:3.5.27-2 179 | ``` 180 | 181 | ## Shell Access 182 | 183 | For debugging and maintenance purposes you may want access the containers shell. If you are using Docker version `1.3.0` or higher you can access a running containers shell by starting `bash` using `docker exec`: 184 | 185 | ```bash 186 | docker exec -it squid bash 187 | ``` 188 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 3.5.27-2 2 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | Squid: 2 | image: sameersbn/squid:3.5.27-2 3 | ports: 4 | - "3128:3128" 5 | volumes: 6 | - /srv/docker/squid/cache:/var/spool/squid 7 | restart: always 8 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | create_log_dir() { 5 | mkdir -p ${SQUID_LOG_DIR} 6 | chmod -R 755 ${SQUID_LOG_DIR} 7 | chown -R ${SQUID_USER}:${SQUID_USER} ${SQUID_LOG_DIR} 8 | } 9 | 10 | create_cache_dir() { 11 | mkdir -p ${SQUID_CACHE_DIR} 12 | chown -R ${SQUID_USER}:${SQUID_USER} ${SQUID_CACHE_DIR} 13 | } 14 | 15 | create_log_dir 16 | create_cache_dir 17 | 18 | # allow arguments to be passed to squid 19 | if [[ ${1:0:1} = '-' ]]; then 20 | EXTRA_ARGS="$@" 21 | set -- 22 | elif [[ ${1} == squid || ${1} == $(which squid) ]]; then 23 | EXTRA_ARGS="${@:2}" 24 | set -- 25 | fi 26 | 27 | # default behaviour is to launch squid 28 | if [[ -z ${1} ]]; then 29 | if [[ ! -d ${SQUID_CACHE_DIR}/00 ]]; then 30 | echo "Initializing cache..." 31 | $(which squid) -N -f /etc/squid/squid.conf -z 32 | fi 33 | echo "Starting squid..." 34 | exec $(which squid) -f /etc/squid/squid.conf -NYCd 1 ${EXTRA_ARGS} 35 | else 36 | exec "$@" 37 | fi 38 | -------------------------------------------------------------------------------- /kubernetes/pod.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: squid 5 | labels: 6 | name: squid 7 | spec: 8 | containers: 9 | - name: squid 10 | image: sameersbn/squid:3.5.27-2 11 | ports: 12 | - containerPort: 3128 13 | protocol: TCP 14 | volumeMounts: 15 | - mountPath: /var/spool/squid 16 | name: data 17 | volumes: 18 | - name: data 19 | emptyDir: {} 20 | -------------------------------------------------------------------------------- /kubernetes/service.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: squid 5 | labels: 6 | name: squid 7 | spec: 8 | type: LoadBalancer 9 | ports: 10 | - port: 3128 11 | targetPort: 3128 12 | protocol: TCP 13 | selector: 14 | name: squid 15 | --------------------------------------------------------------------------------