MemcacheD connection limits inside Docker

1 - Set ulimit flag when running docker container docker run -it --ulimit nofile=4096 memcached

Screenshot

2 - Start memcached with the conn-limit flag which ideally is inherited from 'ulimit -n'

3 - Check your config per screnshot

Example memcahed start script

 1#!/bin/sh
 2# Memcached will run as a process under the memcache user
 3# This container should eb started with teh ulimits flag set to soemthing like '--ulimit nofile=16384'
 4# the memcaced process will inherit the value of ulimit -n OR it will use the MEMCACHED_MAXCONN value
 5# note that MEMCACHED_MAXCONN should not exceed the ulimit value
 6adduser --quiet --system --no-create-home --shell /bin/false memcached || true
 7N_ULIMIT=$(ulimit -n)
 8/usr/bin/memcached \
 9  --user=${MEMCACHED_USER:-memcached} \
10  --listen=${MEMCACHED_HOST:-0.0.0.0} \
11  --port=${MEMCACHED_PORT:-11211} \
12  --memory-limit=${MEMCACHED_MEMUSAGE:-256} \
13  --conn-limit=${MEMCACHED_MAXCONN:-$N_ULIMIT} \
14  --threads=${MEMCACHED_THREADS:-4} \
15  --max-reqs-per-event=${MEMCACHED_REQUESTS_PER_EVENT:-20} \
16  --verbose

Accompanying Dockerfile

1FROM ubuntu:18:04
2
3RUN apt-get -y update \
4&& apt-get install -y memcached\
5&& apt-get -y clean
6
7COPY ./start_memcached.sh /start.sh