2016-11-28 54 views
0

我有一个码头文件,我基于php:5.5.36-apache图像,用于创建图像明确的发展。我的Dockerfile安装了memcached,但我没有运气让memcached开始启动。如果我ssh进入容器并手动启动memcached,它启动就好了。使用官方的PHP码头图像和开始运行memcached

FROM php:5.5.36-apache 

RUN apt-get update \ 
    && apt-get install -y --no-install-recommends \ 
    default-jdk 
RUN apt-get install -y --no-install-recommends autoconf  
RUN apt-get install -y --no-install-recommends python python-pip 

RUN apt-get update && apt-get install -y libmemcached-dev \ 
    apt-utils re2c g++ memcached \ 
    zlib1g zlib1g-dbg zlib1g-dev zlibc mysql-client php5-mysql \ 
    && pecl install memcached \ 
    && docker-php-ext-enable memcached\ 
    && pecl install memcache \ 
    && docker-php-ext-enable memcache 

RUN docker-php-ext-install pdo pdo_mysql 

RUN apt-get install -y gettext 

RUN pip install hgapi 

RUN a2enmod headers \ 
    && a2enmod rewrite 

COPY ./apache2.conf /etc/apache2/apache2.conf 

RUN mkdir /var/www/content 

EXPOSE 11211 

RUN systemctl enable memcached.service 

基本图像是基于Debian:杰西

+0

您滥用RUN。 RUN可以帮助你安装和配置你需要的软件,ADD/COPY添加文件,ENV定义你的环境变量,CMD和ENTRYPOINT启动你的东西,因此它们在Mysql docker镜像中启动mysqld,在Apache docker镜像中启动Apache等等。我的Dockerfile中没有看到CMD或ENTRYPOINT。检查文档https://docs.docker.com/engine/reference/builder/#/cmd和https://docs.docker.com/engine/reference/builder/#/entrypoint – user2915097

+0

我从头开始的图像一个启动apache的CMD,这真是让我困惑的部分。看到我的答案在下面,我现在好多了。 –

回答

0

PHP:36年5月5日的Apache有一个称为的apache2-前景bash脚本,它使用exec推出apache的,该脚本是在调用CMD ["apache2-foreground"] Dockerfile的结尾。这是Docker在启动时执行的一个脚本,并且exec命令将执行权交给系统。

我的解决方案,我非常不雅,我不会建议这样做的任何一种生产服务器是复制apache2-foreground脚本,并启动Apache之前启动memcached。由于这是一个用作本地开发服务器的映像,因此可以满足我的需求。

更新apache2-foreground: #/斌/庆典 设置-e

# Apache gets grumpy about PID files pre-existing 
rm -f /var/run/apache2/apache2.pid 

/etc/init.d/memcached start 
exec apache2 -DFOREGROUND 

然后我代替:

RUN systemctl enable memcached.service 

有:

COPY apache2-foreground /usr/local/bin/ 
0

此链接工作了我在同一个问题与php5,apache2和memcached在Dock中基于Ubuntu erfile:

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

安装主管

RUN apt-get install -y supervisor 

和配置,在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.conf 

RUN 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.conf 

RUN 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.conf 

CMD ["/usr/bin/supervisord"] 

此链接还介绍了如何在容器中运行多个服务:

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