squeakywheel/memcached

By squeakywheel

Updated over 4 years ago

Image

294

memcached | Ubuntu

About Memcached

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. It is a short-term memory for applications. Memcached allows to take memory from parts of a system where you have more than you need and make it accessible to areas where you have less than you need. Read more on the memcached website.

Tags

  • 1.5.22-focal, 1.5.22, 1.5-focal, 1.5, 1-focal, 1, focal, beta - /!\ this is a beta release

Architectures supported

  • amd64, arm64, ppc64el, s390x

Usage

Docker CLI
$ docker run -d --name memcached -e TZ=UTC squeakywheel/memcached:edge

Parameters

ParameterDescription
-e TZ=UTCTimezone.
-e MEMCACHED_CACHE_SIZE=64MBDetermines the size of the cache.
-e MEMCACHED_MAX_CONNECTIONS=1024Determines the maximum number of concurrent connections.
-e MEMCACHED_THREADS=4Determines the number of threads to process requests.
-e MEMCACHED_PASSWORDDefine the password for the root user if another username is provided. By default the authentication is disabled but if this option is passed it becomes enabled.
-e MEMCACHED_USERNAMEDefine a new user. If this option is passed a password is needed to authenticate the new user.
-p 11211Memcached is exposed inside the container on port 11211.

Testing/Debugging

In case you need to debug what it is happening with the container you can run docker logs <name_of_the_container>. But if you want to get access to an interactive shell run:

$ docker exec -it <name_of_the_container> /bin/bash
You can access the memcached instance with telnet from another container (click to expand).
# Create a dedicated network
$ docker network create memcached-net
# Connect the main container to it
$ docker network connect memcached-net memcached
# Run an interactive container with the latest Ubuntu
$ docker run -it --rm --name telnet --network memcached-net ubuntu bash
# Install the telnet cli from within the container
> apt update && apt install telnet -y
# Connect to the memcached instance using telnet
> telnet memcached 11211
Trying 172.30.0.2...
Connected to memcached.
Escape character is '^]'.

From there you can run memcached commands, as documented in their wiki.

$ telnet memcached 11211

There are cases where one might want to pass some memcached command line flags that are not configurable via environment variables. In this case you can pass the flags themselves or a shell script:

$ docker run -d squeakywheel/memcached:edge <flags_or_script_with_flags>
Deploy with Kubernetes

You can use your favorite Kubernetes distribution; if you don't have one, consider installing MicroK8s.

With microk8s running, enable the dns and storage add-ons:

$ microk8s enable dns storage

Use the sample deployment yaml provided here.

Apply the `memcached-deployment.yml` (click to expand)
# memcached-deployment.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: memcached-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: memcached
  template:
    metadata:
      labels:
        app: memcached
    spec:
      containers:
      - name: memcached
        image: squeakywheel/memcached:edge
        env:
        - name: MEMCACHED_CACHE_SIZE
          value: "128"
        - name: MEMCACHED_MAX_CONNECTIONS
          value: "2048"
        - name: MEMCACHED_THREADS
          value: "8"
        - name: MEMCACHED_USERNAME
          value: "john"
        - name: MEMCACHED_PASSWORD
          value: "pAs$wd"
        ports:
        - containerPort: 11211
          name: memcached
          protocol: TCP
$ microk8s kubectl apply -f memcached-deployment.yml

Memcached will be listening on port 31211 in your host.

Bugs and Features request

If you find a bug in our image or want to request a specific feature file a bug here:

https://bugs.launchpad.net/ubuntu-docker-images/+filebug

In the title of the bug add memcached: <reason>.

Make sure to include:

  • The digest of the image you are using, you can find it using this command replacing <tag> with the one you used to run the image:
$ docker images --no-trunc --quiet squeakywheel/memcached:<tag>
  • Reproduction steps for the deployment
  • If it is a feature request, please provide as much detail as possible

Docker Pull Command

docker pull squeakywheel/memcached