docker-library / memcached

Docker Official Image packaging for memcached
http://memcached.org/
BSD 3-Clause "New" or "Revised" License
132 stars 99 forks source link

Healthcheck script #91

Open kaznovac opened 1 year ago

kaznovac commented 1 year ago

As a developer I'd like to have a way to issue a health check on memcached container without modifying the base image (base image has no telnet nor nc)

LaurentGoderre commented 1 year ago

The following works on alpine:

echo "version" | nc -vn -w 1 127.0.0.1 11211

Source: https://book.hacktricks.xyz/network-services-pentesting/11211-memcache

LaurentGoderre commented 1 year ago

And the following works on debian:

echo "version" | (exec 3<>/dev/tcp/localhost/11211; cat >&3; cat <&3; exec 3<&-)
kaznovac commented 1 year ago

@LaurentGoderre Wow, thanks a lot, just what I've needed! (couldn't figure out the 'bidirectional' cat on my own)

I've added timeout to your debian command, so it will not block (just need to figure out the clean way to get the exit code)

echo "version" | (exec 3<>/dev/tcp/localhost/11211; cat >&3; timeout 0.1 cat <&3; exec 3<&-)

If it's ok with you I'd like to create PR to update the documentation of the image (later when I get some free time)

LaurentGoderre commented 1 year ago

Absolutely! That would be awesome!

tianon commented 11 months ago

See https://github.com/docker-library/faq#healthcheck :see_no_evil:

LaurentGoderre commented 11 months ago

@tianon an example could be created here then: https://github.com/docker-library/healthcheck

tianon commented 11 months ago

Agreed! Does memcached have an explicit healthcheck type function we could use, or is just connecting the best we can do? For example, in SQL-based images, I've often used SELECT 1 as a basic health check because I can verify that the output of that query is exactly 1 to know that everything actually worked end-to-end (and it wasn't just something else accepting my connection and quietly doing nothing useful).