0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your info, I went with supervisord. Also, as I said in my post, I know using multiple containers is the better way, but I'm not doing that on purpose as a proof of concept. It's more of a learning experience than anything else, it's not going to production, ever.
0

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

1 Comment

As I said in my post, I know it's the better way, but I'm not doing that on purpose as a proof of concept. It's more of a learning experience than anything else, it's not going to production, ever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.