diff --git a/Dockerfile b/Dockerfile index cc874b7..c7fa51f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM registry.fedoraproject.org/f26-modular/boltron +FROM registry.fedoraproject.org/fedora:rawhide # memcached image for OpenShift. # @@ -12,10 +12,10 @@ LABEL MAINTAINER "Petr Hracek" LABEL summary="High Performance, Distributed Memory Object Cache" \ name="$FGC/$NAME" \ version="0" \ - release="2.$DISTTAG" \ + release="3.$DISTTAG" \ architecture="$ARCH" \ com.redhat.component=$NAME \ - usage="docker run -p 11211:11211 registry.fedoraproject.org/f26-modular/memcached" \ + usage="docker run -p 11211:11211 registry.fedoraproject.org/rawhide/memcached" \ help="Runs memcached, which listens on port 11211. No dependencies. See Help File below for more details." \ description="memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load." \ io.k8s.description="memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load." \ diff --git a/README.md b/README.md index 83659cc..2182789 100644 --- a/README.md +++ b/README.md @@ -2,111 +2,85 @@ Memcached is High Performance, Distributed Memory Object Cache -## Summary +## How to use the container -- Dockerfile - build container image with memcached. -- openshift-template.yml - Template for OpenShift to memcached. - - -## How to use the container over standard 11211 port - -Command for running memcached docker container: - -```bash -docker run -it -e CACHE_SIZE=128 \ - -p 11211:11211 -``` +Pull the image from Docker Hub: -If you would like to increase a CACHE_SIZE use environment variable -e CACHE_SIZE: ```bash -docker run -it -e CACHE_SIZE=128 \ - -p 11211:11211 +$ sudo docker pull registry.fedoraproject.org/memcached:rawhide ``` -## How to run memcached as standalone container +Run the container -Copy memcached-container.service to ```/usr/lib/systemd/user/``` directory ```bash -sudo cp memcached-container.service /usr/lib/systemd/user/ -systemctl --user daemon-reload +docker run -it -p 11211:11211 --name memcached modularitycontainers/memcached ``` -Command for running memcached as standalone container: +If you would like to debug memcached, use container option =e MEMCACHED_DEBUG_MODE: ```bash -systemctl start --user memcached-container +docker run -it -p 11211:11211 +[-e MEMCACHED_DEBUG_MODE] +--name memcached modularitycontainers/memcached ``` -## How to stop memcached as standalone container -Command for stopping memcached as standalone container: +If you would like to change memcached options, like cache_size, connections or threads, use environment variable -e MEMCACHED_CACHE_SIZE, -e MEMCACHED_CONNECTIONS, -e MEMCACHED_THREADS respectively: ```bash -systemctl stop --user memcached-container +docker run -it -p 11211:11211 +[-e MEMCACHED_CACHE_SIZE=] +[-e MEMCACHED_CONNECTIONS=] +[-e MEMCACHED_THREADS=] +--name memcached modularitycontainers/memcached ``` -## How to test the memcached -Commands for testing memcached docker container: +## A demo + +Here is a simple demo how to run memcached + +* Copy systemd service which will take care of memcached container: + ```bash + $ sudo cp -av memcached-container.service /usr/lib/systemd/system/ + $ sudo systemctl daemon-reload + ``` + +* We can start memcached now: + ```bash + $ sudo systemctl start memcached-container + ``` + +* You should be able to test memcached by commands (taken from http://www.journaldev.com/16/memcached-telnet-commands-with-example): + ```bash + set Test 0 100 10 + JournalDev + STORED + get Test + VALUE Test 0 10 + JournalDev + END + replace Test 0 100 4 + Temp + STORED + get Test + VALUE Test 0 4 + Temp + END + stats items + STAT items:1:number 1 + STAT items:1:age 19 + STAT items:1:evicted 0 + STAT items:1:evicted_time 0 + STAT items:1:outofmemory 0 + STAT items:1:tailrepairs 0 + END + flush_all + OK + get Test + END + version + VERSION 1.4.25 + quit + ``` + +## Repository structure -To store data in memcached server with telnet: -```bash -set KEY META_DATA EXPIRY_TIME LENGTH_IN_BYTES -``` - -To get data -```bash -get KEY -``` - -To overwrite existing key -```bash -replace KEY META_DATA EXPIRE_TIME LENGTH_IN_BYTES -``` - -To delete key -```bash -delete KEY -``` - -To get the server statistics -```bash -stats -stats items -stats slabs - -``` - -To clear the metadata statistics -```bash -flush all -``` - -Memcached Server Telnet Example (taken from http://www.journaldev.com/16/memcached-telnet-commands-with-example) -```bash -set Test 0 100 10 -JournalDev -STORED -get Test -VALUE Test 0 10 -JournalDev -END -replace Test 0 100 4 -Temp -STORED -get Test -VALUE Test 0 4 -Temp -END -stats items -STAT items:1:number 1 -STAT items:1:age 19 -STAT items:1:evicted 0 -STAT items:1:evicted_time 0 -STAT items:1:outofmemory 0 -STAT items:1:tailrepairs 0 -END -flush_all -OK -get Test -END -version -VERSION 1.4.25 -quit -``` +- Dockerfile - build container image with memcached. +- openshift-template.yml - Template for OpenShift to memcached. diff --git a/files/memcached.sh b/files/memcached.sh index d7bace4..96bbd16 100755 --- a/files/memcached.sh +++ b/files/memcached.sh @@ -1,22 +1,23 @@ #!/bin/bash -MEMCACHED_CONF="/etc/sysconfig/memcached" +MEMCACHED_ARGS= -if [[ ! -z "${DEBUG_MODE}" ]]; then - rpm -q syslog-ng - if [[ $? -ne 0 ]]; then - dnf -y --setopt=tsflags=nodocs install syslog-ng && \ - dnf -y clean all - syslog-ng - fi +if [[ ! -z "${MEMCACHED_DEBUG_MODE}" ]]; then + MEMCACHED_ARGS+=" -vv" fi -if [[ ! -z "${THREADS_NUM}" ]]; then - grep "OPTIONS=" $MEMCACHED_CONF - if [[ $? -eq 0 ]]; then - echo "OPTIONS="-l 127.0.0.1,::1 -t ${THREADS_NUM}"" >> $MEMCACHED_CONF - fi +if [[ ! -z "${MEMCACHED_CACHE_SIZE}" ]]; then + MEMCACHED_ARGS+=" -m $MEMCACHED_CACHE_SIZE" fi + +if [[ ! -z "${MEMCACHED_CONNECTIONS}" ]]; then + MEMCACHED_ARGS+=" -c $MEMCACHED_CONNECTIONS" +fi + +if [[ ! -z "${MEMCACHED_THREADS}" ]]; then + MEMCACHED_ARGS+=" -t $MEMCACHED_THREADS" +fi + # Run memcached binary -/usr/bin/memcached \ No newline at end of file +/usr/bin/memcached -u daemon $MEMCACHED_ARGS diff --git a/help.md b/help.md index a40d514..8569dde 100644 --- a/help.md +++ b/help.md @@ -9,7 +9,7 @@ memcached - High Performance, Distributed Memory Object Cache. Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. The container itself consists of: - - fedora/24 base image + - fedora/rawhide base image - memcached RPM package Files added to the container during docker build include: /files/memcached.sh @@ -17,14 +17,23 @@ Files added to the container during docker build include: /files/memcached.sh # USAGE To get the memcached container image on your local system, run the following: - docker pull hub.docker.io/phracek/memcached + docker pull registry.fedoraproject.org/memcached:rawhide # ENVIRONMENT VARIABLES The memcached container includes the following environment variables: -CACHE_SIZE=128 - The variable sets size of cached used by memcached. +For turn on verbose mode, use environment variable +-e MEMCACHED_DEBUG_MODE + +For setting cache size, use environment variable +-e MEMCACHED_CACHE_SIZE + +For setting maximum connections, use environment variable +-e MEMCACHED_CONNECTIONS + +For setting maximum threads, use environment variable +-e MEMCACHED_THREADS # SECURITY IMPLICATIONS Lists of security-related attributes that are opened to the host.