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 –

  • Vagrant+Docker: The container started never left the “stopped” state
  • Docker recreates directories on host after reboot
  • Creating a Docker volume at a specific location
  • How to enable colors in a Docker container?
  • Copy files inside of docker image during build
  • How to convert JKS into Docker Registry cert/key?
  • FROM centos:7
    MAINTAINER Some guy <someguy@guysome.org>
    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 docker ps.

    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).

    Setting the 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?

    Thanks.

  • Application in docker with https
  • How to mount special folders in docker-compose.yml
  • Creation of Dockerfile for Android GitLab CI
  • POSIX locale, UnicodeDecodeError
  • Is it possible to isolate docker container in user-defined overlay network from outside internet?
  • kafka monitoring using JMX when running kafka in docker in boot2docker
  • 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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.