Issue getting memcache container to automatically start in Docker
I have a container that is being built that only really contains memcached, and I want it to start once the container is built.
This is my current Docker file –
FROM centos:7 MAINTAINER Some guy <email@example.com> RUN yum update -y RUN yum install -y git https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm RUN yum install -y ansible && yum clean all -y RUN yum install -y memcached RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ rm -f /lib/systemd/system/multi-user.target.wants/*;\ rm -f /etc/systemd/system/*.wants/*;\ rm -f /lib/systemd/system/local-fs.target.wants/*; \ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ rm -f /lib/systemd/system/basic.target.wants/*;\ rm -f /lib/systemd/system/anaconda.target.wants/*; VOLUME [ "/sys/fs/cgroup" ] EXPOSE 11211/tcp 11211/udp CMD ["/usr/bin/memcached"] #CMD ["/usr/bin/memcached -u root"] #CMD ["/usr/bin/memcached", "-D", "FOREGROUND"]
The container builds successfully, but when I try to run the container using the command
docker run -d -i -t -P <image id>, I cannot see the image inside of the list that is returned with
I attempted to have my memcached service run the same way as my httpd container, but I cannot pass in the argument using the -D flag (since its already a daemon im guessing). This is how my httpd CMD was set up –
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
Locally, if I run the command
/usr/bin/memcached -u root it runs as a process, but when I try in the container
CMD it informs me that it cannot find the specified file (having to do with the -u root section I am guessing).
CMD to /bin/bash still did not allow the service to start either.
How can I have my memcached service run and allow it to be seen when I run
docker ps, so that I can open a bash section inside of it?
2 Solutions collect form web for “Issue getting memcache container to automatically start in Docker”
memcached will run in the foreground by default, which is what you want. The
-d option would run memcached as a daemon which would cause the container to exit immediately.
The Dockerfile looks overly complex, try this
FROM centos:7 RUN yum update -y && yum install -y epel-release && yum install -y memcached && yum clean all EXPOSE 11211 CMD ["/usr/bin/memcached","-p","11211","-u","memcached","-m","64"]
Then you can do what you need
$ docker build -t me/memcached . <snipped build> $ CID=$(docker create me/memcached) $ docker start $CID 4ac5afed0641f07f4694c30476cef41104f6fd864c174958b971822005fd292a $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4ac5afed0641 me/memcached "/usr/bin/memcached -" About a minute ago Up 4 seconds 11211/tcp jovial_bardeen $ docker exec $CID ps -ef UID PID PPID C STIME TTY TIME CMD memcach+ 1 0 0 01:03 ? 00:00:00 /usr/bin/memcached -p 11211 -u memcached -m 64 root 10 0 2 01:04 ? 00:00:00 ps -ef $ docker exec -ti $CID bash [root@4ac5afed0641 /]#
Or skip your Dockerfile if it actually only runs memcached and use:
docker run --name my-memcache -d memcached
At least to get your basic set-up going, and then you can update that official image as needed.