MyUsername112358
MyUsername112358

Reputation: 1307

PHP and redis in same docker image

I'm trying to add redis to a php:7.0-apache image, using this Dockerfile:

FROM php:7.0-apache

RUN apt-get update && apt-get -y install build-essential tcl

RUN cd /tmp \
    && curl -O http://download.redis.io/redis-stable.tar.gz \
    && tar xzvf redis-stable.tar.gz \
    && cd redis-stable \
    && make \
    && make install


COPY php.ini /usr/local/etc/php/
COPY public /var/www/html/

RUN chown -R root:www-data /var/www/html
RUN chmod -R 1755 /var/www/html
RUN find /var/www/html -type d -exec chmod 1775 {} +

RUN mkdir -p /var/redis/6379
COPY 6379.conf /etc/redis/6379.conf
COPY redis_6379 /etc/init.d/redis_6379

RUN chmod 777 /etc/init.d/redis_6379

RUN update-rc.d redis_6379 defaults
RUN service apache2 restart
RUN service redis_6379 start

It build and run fines but redis is never started? When I run /bin/bash inside my container and manually input "service redis_6379 start" it works, so I'm assuming my .conf and init.d files are okay.

While I'm aware it'd much easier using docker-compose, I'm specifically trying to avoid having to use it for specific reasons.

Upvotes: 0

Views: 1231

Answers (2)

Geovanny Q. Perez
Geovanny Q. Perez

Reputation: 24

I am agree with @Richard. Use two or more containers according to your needs then --link them, in order to get the things work!

Upvotes: 0

Richard
Richard

Reputation: 1177

There are multiple things wrong here:

  • Starting processes in dockerfile has no effect. A dockerfile builds an image. The processes need to be started at container construction time. This can be done using an entrypoint can be defined in the dockerfile by using ENTRYPOINT. That entrypoint is typically a script that is executed when an actual container is started.
  • There is no init process in docker by default. Issuing service calls will fail without further work. If you need to start multiple processes you can look for the docs of the supervisord program.
  • Running both redis and a webserver in one container is not best practice. For a php application using redis you'd typically have 2 containers - one running redis and one running apache and let them interact via network.

I suggest you read the docker documentation before continuing. All this is described in depth there.

Upvotes: 2

Related Questions