Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from jdeathe/master
Browse files Browse the repository at this point in the history
Release changes ready for centos-6-1.2.0
  • Loading branch information
jdeathe committed Dec 29, 2015
2 parents dd1fc35 + 1b7694e commit cfaf4d6
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 121 deletions.
31 changes: 18 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
# docker run -d --privileged --name varnish.pool-1.1.1 \
# -p 8000:80 -p 8500:8443 \
# jdeathe/centos-ssh-varnish:latest
# ACCESS:
# ACCESS:
# docker exec -it varnish.pool-1.1.1 bash
# ALTERNATIVE ACCESS:
# sudo /usr/bin/nsenter -m -u -i -n -p -t $(/usr/bin/docker inspect \
# --format '{{ .State.Pid }}' varnish.pool-1.1.1) /bin/bash
# =============================================================================
FROM jdeathe/centos-ssh:centos-6
FROM jdeathe/centos-ssh:centos-6-1.4.0

MAINTAINER James Deathe <james.deathe@gmail.com>

Expand All @@ -22,20 +24,23 @@ MAINTAINER James Deathe <james.deathe@gmail.com>
# -----------------------------------------------------------------------------
RUN rpm --nosignature -Uvh http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm \
&& yum --setopt=tsflags=nodocs -y install \
varnish \
varnish-3.0.7-1.el6 \
&& yum versionlock add \
varnish* \
&& rm -rf /var/cache/yum/* \
&& yum clean all

# -----------------------------------------------------------------------------
# Copy files into place
# -----------------------------------------------------------------------------
#RUN mkdir -p /etc/services-config/varnish
ADD etc/varnish-start /etc/
ADD etc/services-config/supervisor/supervisord.conf /etc/services-config/supervisor/
ADD etc/services-config/varnish/docker-default.vcl /etc/services-config/varnish/
ADD etc/services-config/varnish/docker-cluster.vcl /etc/services-config/varnish/

RUN ln -sf /etc/services-config/supervisor/supervisord.conf /etc/supervisord.conf \
&& ln -sf /etc/services-config/varnish/docker-default.vcl /etc/varnish/docker-default.vcl \
&& ln -sf /etc/services-config/varnish/docker-cluster.vcl /etc/varnish/docker-cluster.vcl \
&& chmod +x /etc/varnish-start \
&& chmod 644 /etc/varnish/*.vcl

Expand All @@ -44,20 +49,20 @@ EXPOSE 80 8443
# -----------------------------------------------------------------------------
# Set default environment variables
# -----------------------------------------------------------------------------
ENV NFILES 131072
ENV MEMLOCK 82000
ENV NFILES 131072
ENV NPROCS "unlimited"
ENV VARNISH_PIDFILE /var/run/varnish.pid
ENV VARNISH_LISTEN_ADDRESS 0.0.0.0
ENV VARNISH_LISTEN_PORT 80,0.0.0.0:8443
ENV VARNISH_VCL_CONF /etc/varnish/docker-default.vcl
ENV VARNISH_ADMIN_LISTEN_ADDRESS 127.0.0.1
ENV VARNISH_ADMIN_LISTEN_PORT 6082
ENV VARNISH_SECRET_FILE /etc/varnish/secret
ENV VARNISH_TTL 120
ENV VARNISH_MIN_THREADS 50
ENV VARNISH_LISTEN_ADDRESS 0.0.0.0
ENV VARNISH_LISTEN_PORT 80,0.0.0.0:8443
ENV VARNISH_MAX_THREADS 1000
ENV VARNISH_THREAD_TIMEOUT 120
ENV VARNISH_MIN_THREADS 50
ENV VARNISH_PIDFILE /var/run/varnish.pid
ENV VARNISH_SECRET_FILE /etc/varnish/secret
ENV VARNISH_STORAGE file,/var/lib/varnish/varnish_storage.bin,1G
ENV VARNISH_THREAD_TIMEOUT 120
ENV VARNISH_TTL 120
ENV VARNISH_VCL_CONF /etc/varnish/docker-default.vcl

CMD ["/usr/bin/supervisord", "--configuration=/etc/supervisord.conf"]
2 changes: 1 addition & 1 deletion README-short.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CentOS-6 6.6 x86_64 / Varnish Cache.
CentOS-6 6.7 x86_64 / Varnish Cache.
79 changes: 65 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
centos-ssh-varnish
==================

Docker Image including CentOS-6 6.6 x86_64 and Varnish Cache 3.0.
Docker Image including CentOS-6 6.7 x86_64 and Varnish Cache 3.0.

Supports custom configuration via a configuration data volume.

Expand All @@ -13,16 +13,25 @@ Included in the build is the EPEL repository and SSH, vi and MySQL are installed

[Supervisor](http://supervisord.org/) is used to start varnishd (and optionally the sshd) daemon when a docker container based on this image is run. To enable simple viewing of stdout for the sshd subprocess, supervisor-stdout is included. This allows you to see output from the supervisord controlled subprocesses with `docker logs <docker-container-name>`.

SSH is not required in order to access a terminal for the running container the preferred method is to use Command Keys and the nsenter command. See [command-keys.md](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/command-keys.md) for details on how to set this up.

If enabling and configuring SSH access, it is by public key authentication and, by default, the [Vagrant](http://www.vagrantup.com/) [insecure private key](https://github.com/mitchellh/vagrant/blob/master/keys/vagrant) is required.

### SSH Alternatives

SSH is not required in order to access a terminal for the running container. The simplest method is to use the docker exec command to run bash (or sh) as follows:

```
$ docker exec -it <docker-name-or-id> bash
```

For cases where access to docker exec is not possible the preferred method is to use Command Keys and the nsenter command. See [command-keys.md](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/command-keys.md) for details on how to set this up.

## Quick Example

Run up a container named ```varnish.pool-1.1.1``` from the docker image ```jdeathe/centos-ssh-varnish``` on port 80 of your docker host. 1 backend host is defined with the IP address 172.17.8.101; this is required to identify the backend hosts from within the Varnish VCL file.

```
$ docker run -d \
--privileged \
--name varnish.pool-1.1.1 \
-p 80:80 \
--add-host backend-1:172.17.8.101 \
Expand Down Expand Up @@ -74,42 +83,52 @@ $ mkdir -p /etc/services-config/varnish.pool-1.1.1

Create the data volume, mounting the applicable docker host's configuration directories to the associated */etc/services-config/* sub-directories in the docker container. Docker will pull the busybox:latest image if you don't already have it available locally.

If enabling the SSH service in the supervisor configuration you can define a persistent authorised key for SSH access by mounting the ssh.pool-1 directory and adding the key there.

```
$ docker run \
--name volume-config.varnish.pool-1.1.1 \
-v /etc/services-config/ssh.pool-1/ssh:/etc/services-config/ssh \
-v /etc/services-config/varnish.pool-1.1.1/supervisor:/etc/services-config/supervisor \
-v /etc/services-config/varnish.pool-1.1.1/varnish:/etc/services-config/varnish \
busybox:latest \
/bin/true
```

If enabling the SSH service in the supervisor configuration you can define a persistent authorised key for SSH access by mounting the ssh.pool-1 directory and adding the key there.
### Running

To run the a docker container from this image you can use the included [run.sh](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/run.sh) and [run.conf](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/run.conf) scripts. The helper script will stop any running container of the same name, remove it and run a new daemonised container on an unspecified host port. Alternatively you can use the following to make the http service available on port 8000 and offloaded https on port 8500 of the docker host. The environment variable ```VARNISH_STORAGE``` has been used to set up a 256M memory based storage instead of the default file based type.

#### Using environment variables

```
$ docker run \
--name volume-config.varnish.pool-1.1.1 \
-v /etc/services-config/ssh.pool-1:/etc/services-config/ssh \
-v /etc/services-config/varnish.pool-1.1.1/supervisor:/etc/services-config/supervisor \
-v /etc/services-config/varnish.pool-1.1.1/varnish:/etc/services-config/varnish \
busybox:latest \
/bin/true
$ docker stop varnish.pool-1.1.1 && \
docker rm varnish.pool-1.1.1
$ docker run -d \
--privileged \
--name varnish.pool-1.1.1 \
-p 8000:80 \
-p 8500:8443 \
--env "VARNISH_STORAGE=malloc,256M" \
--add-host backend-1:172.17.8.101 \
jdeathe/centos-ssh-varnish:latest
```

### Running
#### Using configuration volume

To run the a docker container from this image you can use the included [run.sh](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/run.sh) and [run.conf](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/run.conf) scripts. The helper script will stop any running container of the same name, remove it and run a new daemonised container on an unspecified host port. Alternatively you can use the following to make the service available on port 8000 of the docker host. 4 backend hosts are defined with the IP range 172.17.8.101 - 172.17.8.104.
By default a single backend host is required. In this example 3 backend hosts are defined with the IP range 172.17.8.101 - 172.17.8.103. In this case the docker-default.vcl would require updating to handle more than one backend host as described in the (Custom Configuration)[https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/README.md#custom-configuration] section below.

```
$ docker stop varnish.pool-1.1.1 && \
docker rm varnish.pool-1.1.1
$ docker run -d \
--privileged \
--name varnish.pool-1.1.1 \
-p 8000:80 \
-p 8500:8443 \
--add-host backend-1:172.17.8.101 \
--add-host backend-2:172.17.8.102 \
--add-host backend-3:172.17.8.103 \
--add-host backend-4:172.17.8.104 \
--volumes-from volume-config.varnish.pool-1.1.1 \
jdeathe/centos-ssh-varnish:latest
```
Expand All @@ -120,6 +139,34 @@ Now you can verify it is initialised and running successfully by inspecting the
$ docker logs varnish.pool-1.1.1
```

#### Runtime Environment Variables

There are several environmental variables defined at runtime which allows the operator to customise the running container. This may become necessary under special circumstances and the following show those that are most likely to be considered for review, the rest should be left unaltered and for clarification refer to the [varnishd documentation](https://www.varnish-cache.org/docs/3.0/reference/varnishd.html).

##### 1. (-a) VARNISH_LISTEN_ADDRESS & VARNISH_LISTEN_PORT

```VARNISH_LISTEN_ADDRESS``` is set to 0.0.0.0 by default and should not be altered. VARNISH_LISTEN_PORT has been used to add the listening port 80 and also to set a second listening address and port of 0.0.0.0:8448 for the special case of HTTPS traffic that has been terminated by an upstream load-balancer.

##### 2. (-P) VARNISH_PIDFILE

This should not be changed and will be ignored if set. The varnish-start script will set the PID file to the default /var/run/varnish.pid file.

##### 3. (-f) VARNISH_VCL_CONF

The Varnish VLC configuration file to load is set using ```VARNISH_VCL_CONF```. The default configuration supplied is located at the path /etc/varnish/docker-default.vcl and an alternative example is also available under /etc/varnish/docker-cluster.vcl.

##### 4. (-t) VARNISH_TTL

The ```VARNISH_TTL``` can be used to set a hard minimum time to live for cached documents. The default is 120 seconds.

##### 5. (-w) VARNISH_MIN_THREADS, VARNISH_MAX_THREADS & VARNISH_THREAD_TIMEOUT

Start at least ```VARNISH_MIN_THREADS``` but no more than ```VARNISH_MAX_THREADS``` worker threads with the ```VARNISH_THREAD_TIMEOUT``` idle timeout.

##### 6. (-s) VARNISH_STORAGE

Use ```VARNISH_STORAGE``` to specify the storage backend. See the [varnishd documentation](https://www.varnish-cache.org/docs/3.0/reference/varnishd.html#storage-types) for the types and parameters available. The default is a file type backend but it is recommended to use malloc if there is enough RAM available.

### Custom Configuration

If using the optional data volume for container configuration you are able to customise the configuration. In the following examples your custom docker configuration files should be located on the Docker host under the directory ```/etc/service-config/<container-name>/``` where ```<container-name>``` should match the applicable container name such as "varnish.pool-1.1.1" in the examples.
Expand All @@ -128,6 +175,10 @@ If using the optional data volume for container configuration you are able to cu

Varnish can be configured via the docker-default.vcl.

#### [varnish/docker-cluster.vcl](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/etc/services-config/varnish/docker-cluster.vcl)

An example of a Varnish configuration that uses 3 backend host nodes.

#### [supervisor/supervisord.conf](https://github.com/jdeathe/centos-ssh-varnish/blob/centos-6/etc/services-config/supervisor/supervisord.conf)

The supervisor service's configuration can also be overridden by editing the custom supervisord.conf file. It shouldn't be necessary to change the existing configuration here but you could include more [program:x] sections to run additional commands at startup.
10 changes: 5 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

# Change working directory
DIR_PATH="$( cd "$( echo "${0%/*}" )"; pwd )"
if [[ $DIR_PATH == */* ]]; then
DIR_PATH="$( if [ "$( echo "${0%/*}" )" != "$( echo "${0}" )" ] ; then cd "$( echo "${0%/*}" )"; fi; pwd )"
if [[ $DIR_PATH == */* ]] && [[ $DIR_PATH != "$( pwd )" ]] ; then
cd $DIR_PATH
fi

Expand All @@ -12,11 +12,11 @@ source build.conf

show_docker_image ()
{
NAME=$1
NAME_PARTS=(${NAME//:/ })
local NAME=$1
local NAME_PARTS=(${NAME//:/ })

# Set 'latest' tag if no tag requested
if [ ${#NAME_PART[@]} == 1 ]; then
if [ ${#NAME_PARTS[@]} == 1 ]; then
NAME_PARTS[1]='latest'
fi

Expand Down
42 changes: 29 additions & 13 deletions run.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,36 @@ DOCKER_IMAGE_TAG=latest
SERVICE_UNIT_NAME=varnish
SERVICE_UNIT_APP_GROUP=app-1
SERVICE_UNIT_SHARED_GROUP=pool-1
SERVICE_UNIT_PORT_ID=1
SERVICE_UNIT_LOCAL_ID=1
SERVICE_UNIT_INSTANCE=1

MOUNT_PATH_DATA=/home/core/share
MOUNT_PATH_CONFIG=/etc/services-config
# Mac hosts need to be in User writable directory
if [ "$(uname)" == "Darwin" ]; then
MOUNT_PATH_CONFIG=~/services-config
fi

DOCKER_IMAGE_REPOSITORY_NAME=${DOCKER_USER}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
DOCKER_NAME=${SERVICE_UNIT_NAME}.${SERVICE_UNIT_SHARED_GROUP}.${SERVICE_UNIT_PORT_ID}.${SERVICE_UNIT_INSTANCE}

BACKEND_HOST_1=172.17.8.101
BACKEND_HOST_2=172.17.8.102
BACKEND_HOST_3=172.17.8.103
BACKEND_HOST_4=172.17.8.104
BACKEND_HOST_5=172.17.8.105
BACKEND_HOST_6=172.17.8.106
BACKEND_HOST_7=172.17.8.107
BACKEND_HOST_8=172.17.8.108
BACKEND_HOST_9=172.17.8.109
DOCKER_NAME=${SERVICE_UNIT_NAME}.${SERVICE_UNIT_SHARED_GROUP}.${SERVICE_UNIT_LOCAL_ID}.${SERVICE_UNIT_INSTANCE}

VOLUME_CONFIG_NAME=volume-config.${DOCKER_NAME}

DOCKER_HOST_IP_DEFAULT=${DOCKER_HOST_IP_DEFAULT:-192.168.99.100}
DOCKER_HOST_IP_CLUSTER_01=${DOCKER_HOST_IP_CLUSTER_01:-172.17.8.101}
DOCKER_HOST_IP_CLUSTER_02=${DOCKER_HOST_IP_CLUSTER_02:-172.17.8.102}
DOCKER_HOST_IP_CLUSTER_03=${DOCKER_HOST_IP_CLUSTER_03:-172.17.8.103}

# default - 1 node
# cluster - 3 node cluster
DOCKER_HOST_TYPE=default

VARNISH_STORAGE=file,/var/lib/varnish/varnish_storage.bin,1G
# Uncomment 1 of the below to override the storage settings and use memory
# instead of disk based cache.
#VARNISH_STORAGE=malloc,256M
#VARNISH_STORAGE=malloc,1024M

VARNISH_VCL_CONF=/etc/varnish/docker-default.vcl
# Uncomment below to use the cluster configuration. Requires 3 backend host
# nodes and DOCKER_HOST_TYPE set to "cluster".
#VARNISH_VCL_CONF=/etc/varnish/docker-cluster.vcl
Loading

0 comments on commit cfaf4d6

Please sign in to comment.