Docker Community Forums

Share and learn in the Docker community.

Newbie: the curious case of memcached [Errno 111] Connection refused


(Fxenosmilus) #1

Hi everybody,

my first attempt @ running docker, a django webservice, with postgresql and memcached in three containers,
(MacOSX High Sierra version 10.13.6, Docker version 18.06.1-ce, build e68fc7a):
Django 2.1 (python3.7, psycopg, pymemcached), postgresql with memcached,

My setup:

Dockerfile for the django webservice image.

FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /dingus
WORKDIR /dingus
ADD requirements.txt /dingus/
RUN pip install -r requirements.txt
ADD . /dingus/
EXPOSE 8000

docker-compose.yml

version: ‘3’

services:
db:
restart: always
image: postgres
ports:
- ‘5432:5432’
memcached:
image: memcached
ports:
- ‘11211:11211’
entrypoint:
- memcached
- -m 64
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/dingus
ports:
- ‘8000:8000’
depends_on:
- db
- memcached
restart: always
entrypoint: /dingus/web_entrypoint.sh

The web entrypoint.sh runs a migration, adds some fixtures and this works all nicely.
The postgresql container runs beautifully, the django webserver container works as expected, but memcached can not be reached.
The memcached entrypoint was one of the many attempts found googling possible solutions to an inaccessable memcached port 11211 on localhost (nor ‘memcached’, nor any other alias configured).

The problem is illustrated with the python trace:

File “/usr/local/lib/python3.7/site-packages/pymemcache/client/base.py”, line 258, in _connect
web_1 | sock.connect(self.server)
web_1 | ConnectionRefusedError: [Errno 111] Connection refused

The memcached container log contains “Signal handled: Terminated.”, but i am not sure whatever that means.
Connecting to localhost:11211 with curl: (52) Empty reply from server, which might well be, but not connection refused. As you can tell, i am stumbling in the dark … :slight_smile:

self.server holds a tuple with (server, port), in this case (127.0.0.1, 11211), assuming connecting to localhost:11211 would reach the memcached process. I have read until blue in the face, and tried -({everything})-, but no dice.

Question

What am i doing wrong?
How can i improve this setup in order to make this just work?

Thank you for looking into this …

Inspection reports

docker inspect dingus_memcached_1
[
{
“Id”: “aa15564675cd097e08e5300e8d86bce5ec81bd28cf2c3f81cb45ad7c5012a309”,
“Created”: “2018-10-09T15:23:23.12688337Z”,
“Path”: “memcached”,
“Args”: [
“-m 64”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 56880,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2018-10-09T15:30:00.78160528Z”,
“FinishedAt”: “2018-10-09T15:29:56.059304076Z”
},
“Image”: “sha256:9bf7d35db978ba7c579dde52daa3aafec3c62dc1b690b86395ff78bb28e13594”,
“ResolvConfPath”: “/var/lib/docker/containers/aa15564675cd097e08e5300e8d86bce5ec81bd28cf2c3f81cb45ad7c5012a309/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/aa15564675cd097e08e5300e8d86bce5ec81bd28cf2c3f81cb45ad7c5012a309/hostname”,
“HostsPath”: “/var/lib/docker/containers/aa15564675cd097e08e5300e8d86bce5ec81bd28cf2c3f81cb45ad7c5012a309/hosts”,
“LogPath”: “/var/lib/docker/containers/aa15564675cd097e08e5300e8d86bce5ec81bd28cf2c3f81cb45ad7c5012a309/aa15564675cd097e08e5300e8d86bce5ec81bd28cf2c3f81cb45ad7c5012a309-json.log”,
“Name”: “/dingus_memcached_1”,
“RestartCount”: 0,
“Driver”: “overlay2”,
“Platform”: “linux”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: [],
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “dingus_default”,
“PortBindings”: {
“11211/tcp”: [
{
“HostIp”: “”,
“HostPort”: “11211”
}
]
},
“RestartPolicy”: {
“Name”: “”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: [],
“CapAdd”: null,
“CapDrop”: null,
“Dns”: null,
“DnsOptions”: null,
“DnsSearch”: null,
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “shareable”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: null,
“DeviceCgroupRules”: null,
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: null,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0,
“MaskedPaths”: [
“/proc/acpi”,
“/proc/kcore”,
“/proc/keys”,
“/proc/latency_stats”,
“/proc/timer_list”,
“/proc/timer_stats”,
“/proc/sched_debug”,
“/proc/scsi”,
“/sys/firmware”
],
“ReadonlyPaths”: [
“/proc/asound”,
“/proc/bus”,
“/proc/fs”,
“/proc/irq”,
“/proc/sys”,
“/proc/sysrq-trigger”
]
},
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay2/ba92db8cadb61da04f11a971875f2d939d4a410a528b2b75426becd134eedb44-init/diff:/var/lib/docker/overlay2/938ded878921449dbfd517da9b13570f696330da44aa08c4f16e12873b69d629/diff:/var/lib/docker/overlay2/d6b8fc3c919bff75d7b4bd36f1bdc8be5c921b4d22f7a9b5ed747de143411144/diff:/var/lib/docker/overlay2/ec64d9997dbd26825ce4102fdd5e422ab917d478276e07a4e82570561b0e284e/diff:/var/lib/docker/overlay2/ca7eaed43c005c8bd33f5023751f50f315f9ebc51f4cca328a1bb32642378273/diff:/var/lib/docker/overlay2/668294987bbfab00485ab74214aa36c4ddc8f69f58e1a45b5a6cfa060abb9cb6/diff”,
“MergedDir”: “/var/lib/docker/overlay2/ba92db8cadb61da04f11a971875f2d939d4a410a528b2b75426becd134eedb44/merged”,
“UpperDir”: “/var/lib/docker/overlay2/ba92db8cadb61da04f11a971875f2d939d4a410a528b2b75426becd134eedb44/diff”,
“WorkDir”: “/var/lib/docker/overlay2/ba92db8cadb61da04f11a971875f2d939d4a410a528b2b75426becd134eedb44/work”
},
“Name”: “overlay2”
},
“Mounts”: [],
“Config”: {
“Hostname”: “aa15564675cd”,
“Domainname”: “”,
“User”: “memcache”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“11211/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“MEMCACHED_VERSION=1.5.10”,
“MEMCACHED_SHA1=fff9351b360a09497cd805d3e4c1ffbe860d067d”
],
“Cmd”: null,
“Image”: “memcached”,
“Volumes”: null,
“WorkingDir”: “”,
“Entrypoint”: [
“memcached”,
“-m 64”
],
“OnBuild”: null,
“Labels”: {
“com.docker.compose.config-hash”: “e4a3350c29157db4f7b3836259fb7b23a429ce363ca67d3dd1e6b0f57963c5f6”,
“com.docker.compose.container-number”: “1”,
“com.docker.compose.oneoff”: “False”,
“com.docker.compose.project”: “dingus”,
“com.docker.compose.service”: “memcached”,
“com.docker.compose.version”: “1.22.0”
}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “6b41c6bf8fd270275c67ceaf553cf21f9e7aae627ed32851650f5a4916efbbec”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {
“11211/tcp”: [
{
“HostIp”: “0.0.0.0”,
“HostPort”: “11211”
}
]
},
“SandboxKey”: “/var/run/docker/netns/6b41c6bf8fd2”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “”,
“Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “”,
“IPPrefixLen”: 0,
“IPv6Gateway”: “”,
“MacAddress”: “”,
“Networks”: {
“dingus_default”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: [
“memcached”,
“aa15564675cd”
],
“NetworkID”: “f621b39b6c43d0c08da7ea154b08d2776edd26be94a60ea31cfbb55fbd987e8b”,
“EndpointID”: “41c03698e2fe4587abceac089214971533f940133caecc302c493b8e59a56a39”,
“Gateway”: “172.19.0.1”,
“IPAddress”: “172.19.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:13:00:02”,
“DriverOpts”: null
}
}
}
}
]

docker inspect dingus_db_1
[
{
“Id”: “d5a62dadc45dbef1471045609c23818f96b9f0c2f56ba5736586a85ce9621573”,
“Created”: “2018-10-09T15:23:23.114909986Z”,
“Path”: “docker-entrypoint.sh”,
“Args”: [
“postgres”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 56864,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2018-10-09T15:30:00.776539133Z”,
“FinishedAt”: “2018-10-09T15:29:56.08541515Z”
},
“Image”: “sha256:084ec18124c8ccb08c7df98492db211f19a6a3d9e159cc88d1281c634b90bb87”,
“ResolvConfPath”: “/var/lib/docker/containers/d5a62dadc45dbef1471045609c23818f96b9f0c2f56ba5736586a85ce9621573/resolv.conf”,
“HostnamePath”: “/var/lib/docker/containers/d5a62dadc45dbef1471045609c23818f96b9f0c2f56ba5736586a85ce9621573/hostname”,
“HostsPath”: “/var/lib/docker/containers/d5a62dadc45dbef1471045609c23818f96b9f0c2f56ba5736586a85ce9621573/hosts”,
“LogPath”: “/var/lib/docker/containers/d5a62dadc45dbef1471045609c23818f96b9f0c2f56ba5736586a85ce9621573/d5a62dadc45dbef1471045609c23818f96b9f0c2f56ba5736586a85ce9621573-json.log”,
“Name”: “/dingus_db_1”,
“RestartCount”: 0,
“Driver”: “overlay2”,
“Platform”: “linux”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: [],
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “dingus_default”,
“PortBindings”: {
“5432/tcp”: [
{
“HostIp”: “”,
“HostPort”: “5432”
}
]
},
“RestartPolicy”: {
“Name”: “always”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: [],
“CapAdd”: null,
“CapDrop”: null,
“Dns”: null,
“DnsOptions”: null,
“DnsSearch”: null,
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “shareable”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
0,
0
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: null,
“DeviceCgroupRules”: null,
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: null,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0,
“MaskedPaths”: [
“/proc/acpi”,
“/proc/kcore”,
“/proc/keys”,
“/proc/latency_stats”,
“/proc/timer_list”,
“/proc/timer_stats”,
“/proc/sched_debug”,
“/proc/scsi”,
“/sys/firmware”
],
“ReadonlyPaths”: [
“/proc/asound”,
“/proc/bus”,
“/proc/fs”,
“/proc/irq”,
“/proc/sys”,
“/proc/sysrq-trigger”
]
},
“GraphDriver”: {
“Data”: {
“LowerDir”: “/var/lib/docker/overlay2/0ebc014dd5688dd3589005b671d5c76135705d24dbd9707c9585d558c488d047-init/diff:/var/lib/docker/overlay2/bd0190d136c7ed81333684210311ac57f5660f9b52eaabdf4729863fc8e9b4a7/diff:/var/lib/docker/overlay2/1a0a4d79e3a295ac7bfd99128d726f2af6910d42c8b2d649200f2badaa60865a/diff:/var/lib/docker/overlay2/0a3ba26b478063315bee49fb1075e1dce27fad2a9d046f23bd8b039c80d26de0/diff:/var/lib/docker/overlay2/a764d559de5bf6429498c20133f7957701e90221ea447ef93d4d24582cda88f6/diff:/var/lib/docker/overlay2/511089c38a1de797353b481889911c439cf39ed07697f4c8216e2837e07a2576/diff:/var/lib/docker/overlay2/3f39b46457e622dcb4e4b9aa6b8d45947285ef79c9f295617420101d1948c11b/diff:/var/lib/docker/overlay2/6c04d9849b13b1b21bd1506280019f052213445eb5f1aaf81c6f67e956603e95/diff:/var/lib/docker/overlay2/8302c0519e882d840f2e3b278467784005e9bec86a82ddb6a1fc86082f0fa7c7/diff:/var/lib/docker/overlay2/c2ecc82886659be62e2b3a2a6219c9f0c65c44827c76aeffd9209c887c7024f3/diff:/var/lib/docker/overlay2/d931a4811d0c2b7d9b1fa0c3ea47422c9cef37dea00586879fd971690d65afeb/diff:/var/lib/docker/overlay2/48623fecacd14a57e9a377eebb495ed37b07e4e6eb599038099fc2a60558dc72/diff:/var/lib/docker/overlay2/0c0130f9afc7827b8edf28d09b50836ea41f14ebe4bd3b0fe7ac6c4df90c7b30/diff:/var/lib/docker/overlay2/5940bdc85ee3319a7262f1386c581011ec9eba9c13fc4570d93f5cf7f8e05ac7/diff:/var/lib/docker/overlay2/668294987bbfab00485ab74214aa36c4ddc8f69f58e1a45b5a6cfa060abb9cb6/diff”,
“MergedDir”: “/var/lib/docker/overlay2/0ebc014dd5688dd3589005b671d5c76135705d24dbd9707c9585d558c488d047/merged”,
“UpperDir”: “/var/lib/docker/overlay2/0ebc014dd5688dd3589005b671d5c76135705d24dbd9707c9585d558c488d047/diff”,
“WorkDir”: “/var/lib/docker/overlay2/0ebc014dd5688dd3589005b671d5c76135705d24dbd9707c9585d558c488d047/work”
},
“Name”: “overlay2”
},
“Mounts”: [
{
“Type”: “volume”,
“Name”: “08caf4c4759dcf39e086126c6717876f1979bbeaa82edfb04b6e975d661823c6”,
“Source”: “/var/lib/docker/volumes/08caf4c4759dcf39e086126c6717876f1979bbeaa82edfb04b6e975d661823c6/_data”,
“Destination”: “/var/lib/postgresql/data”,
“Driver”: “local”,
“Mode”: “”,
“RW”: true,
“Propagation”: “”
}
],
“Config”: {
“Hostname”: “d5a62dadc45d”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“5432/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/10/bin”,
“GOSU_VERSION=1.10”,
“LANG=en_US.utf8”,
“PG_MAJOR=10”,
“PG_VERSION=10.5-1.pgdg90+1”,
“PGDATA=/var/lib/postgresql/data”
],
“Cmd”: [
“postgres”
],
“ArgsEscaped”: true,
“Image”: “postgres”,
“Volumes”: {
“/var/lib/postgresql/data”: {}
},
“WorkingDir”: “”,
“Entrypoint”: [
“docker-entrypoint.sh”
],
“OnBuild”: null,
“Labels”: {
“com.docker.compose.config-hash”: “c0b1237863bcd2edf8b2eb962912b947504b0082cb4883631bb225109a055a4d”,
“com.docker.compose.container-number”: “1”,
“com.docker.compose.oneoff”: “False”,
“com.docker.compose.project”: “dingus”,
“com.docker.compose.service”: “db”,
“com.docker.compose.version”: “1.22.0”
}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “af5312bcfdd6ed45dcbc14b5fda53f9877d2a8d7d738637ddf50610597a88050”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {
“5432/tcp”: [
{
“HostIp”: “0.0.0.0”,
“HostPort”: “5432”
}
]
},
“SandboxKey”: “/var/run/docker/netns/af5312bcfdd6”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “”,
“Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “”,
“IPPrefixLen”: 0,
“IPv6Gateway”: “”,
“MacAddress”: “”,
“Networks”: {
“dingus_default”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: [
“db”,
“d5a62dadc45d”
],
“NetworkID”: “f621b39b6c43d0c08da7ea154b08d2776edd26be94a60ea31cfbb55fbd987e8b”,
“EndpointID”: “b53d09c3a538057aa530181c0dc992a9bdce73bf55ea8250d655db8d1a8c9323”,
“Gateway”: “172.19.0.1”,
“IPAddress”: “172.19.0.3”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:13:00:03”,
“DriverOpts”: null
}
}
}
}
]


(Bodnar) #2

My memcached definition currently looks like this (with no issues)

memcached:
image: memcached:alpine
ports:
  - 11211:11211
command: ["memcached"]

(Fxenosmilus) #3

ah, command, right. Thank you very much, will try it now :slight_smile: