How to flush all of the cached contents of Docker container memcached from command line without restarting memcached?
3 Answers
docker exec -it $MEMCACHE_CONTAINER_ID bash -c "echo flush_all > /dev/tcp/localhost/11211"
-
When using memcached:alpine. You will get:
exec: "bash": executable file not found in $PATH: unknown
Feb 12, 2022 at 23:16
Assuming that you have the memcahed port 11211
exposed. You can flush the cache via either telnet
or nc
and sending flush_all
echo flush_all | nc localhost 11211
OK
You can replace localhost, with the machine hostname if you are not executing the command on the same machine where the container is running.
-
1
-
@caot Execute nc or telnet from the host machine, not inside the container.– yamenkMar 21, 2018 at 14:05
Try to use the following (also works on alpine docker image):
docker exec -it $DOCKER_CONTAINER_ID sh -c "echo flush_all | nc localhost 11211"