Using the official php docker image and running memcached on start Using the official php docker image and running memcached on start docker docker

Using the official php docker image and running memcached on start


This link worked for me for the same issue with php5, apache2 and memcached in a Dockerfile based on ubuntu:

https://github.com/moby/moby/issues/5137

Install supervisor

RUN apt-get install -y supervisor

and config that in Dockerfile:

RUN touch  /etc/supervisor/conf.d/supervisord.conf && \    echo "[supervisord]" >> /etc/supervisor/conf.d/supervisord.conf && \    echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.confRUN touch /etc/supervisor/conf.d/memcached.conf && \    echo "[program:memcache]" >> /etc/supervisor/conf.d/memcached.conf && \    echo "command=/usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -DFOREGROUND" >> /etc/supervisor/conf.d/memcached.conf && \    echo "autostart=true" >> /etc/supervisor/conf.d/memcached.conf && \    echo "autorestart=true" >> /etc/supervisor/conf.d/memcached.confRUN touch /etc/supervisor/conf.d/apache2.conf && \    echo "[program:apache2]" >> /etc/supervisor/conf.d/apache2.conf && \    echo 'command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"' >> /etc/supervisor/conf.d/apache2.conf && \    echo "autostart=true" >> /etc/supervisor/conf.d/apache2.conf && \    echo "autorestart=true" >> /etc/supervisor/conf.d/apache2.confCMD ["/usr/bin/supervisord"]

This link also explains how to run multiple services in a container:

https://docs.docker.com/engine/admin/multi-service_container/


php:5.5.36-apache has a bash script called apache2-foreground which uses exec to launch apache, that script is called with CMD ["apache2-foreground"] at the end of the Dockerfile. This is the one script that will be executed by Docker on start and the exec command passes execution off to the system.

My solution which my very well be inelegant and I would not suggest doing this with any kind of production server is to copy the apache2-foreground script and start memcached before apache is started. Since this is an image to use as a local development server this meets my needs.

The updated apache2-foreground: #!/bin/bash set -e

# Apache gets grumpy about PID files pre-existingrm -f /var/run/apache2/apache2.pid/etc/init.d/memcached startexec apache2 -DFOREGROUND

Then I replaced:

RUN systemctl enable memcached.service

with:

COPY apache2-foreground /usr/local/bin/