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

I have a docker file that I am basing from the php:5.5.36-apache image, for creating image expressly for development. My Dockerfile installs memcached but I am having no luck getting memcached to start on boot. If I ssh into the container and start memcached manually, it starts just fine.
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
The base image is based on debian:jessie

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.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"]
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-existing
rm -f /var/run/apache2/apache2.pid
/etc/init.d/memcached start
exec apache2 -DFOREGROUND
Then I replaced:
RUN systemctl enable memcached.service
with:
COPY apache2-foreground /usr/local/bin/

Related

Can't install pdo_mysql with docker-php-ext-install

I need help, I can’t install pdo_mysql, ampq or opcache with docker-php-ext-install. I prepared a docker project on a local PC (Mac OSX). On the local PC after build docker image is the final PHP configuration right. When I deploy the project config to the remote Debian server after building it, I have a completely different PHP version (phpinfo). Missing extensions opcache, pdo_mysql, ampq.
I tried to configure it differently and deleted the docker cache on the server, but it didn’t help.
docker system prune -a
My PHP dockerfile:
FROM php:7.4-fpm
WORKDIR /var/www/symfony
RUN apt-get update \
&& docker-php-ext-install mysqli pdo pdo_mysql \
&& docker-php-ext-enable pdo_mysql
RUN apt update && apt-get udpate \
&& apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip libxslt1-dev\
&& docker-php-ext-install intl \
&& pecl install apcu \
&& docker-php-ext-enable apcu \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip \
&& docker-php-ext-install xsl
RUN apt-get update \
&& docker-php-ext-install opcache
RUN apt-get update \
&& apt-get install -y \
librabbitmq-dev \
libssh-dev \
&& pecl install amqp \
&& docker-php-ext-enable amqp
RUN apt-get update && \
apt-get install -y libxml2-dev \
&& docker-php-ext-install soap
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Node.js
RUN curl -sL https://deb.nodesource.com/setup_14.x -o node_setup.sh && \
bash node_setup.sh && \
apt-get install -y nodejs && \
npm install npm -g
# Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -y yarn
RUN apt-get update && apt-get install -y cron
ADD ./crontab /etc/cron.d/crontab
#
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontab
RUN crontab /etc/cron.d/crontab
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
RUN apt-get update && apt-get install -y supervisor
ADD ./supervisord.conf /etc/supervisor/
# Copy docker entrypoint file
COPY ./entrypoint.sh /entrypoint.sh
# Docker init
RUN ["chmod", "+x", "/entrypoint.sh"]
Not sure if it's a solution to your issue, but let's see.
From https://hub.docker.com/_/php:
If you are having difficulty figuring out which Debian or Alpine packages need to be installed before docker-php-ext-install, then have a look at the install-php-extensions project. This script builds upon the docker-php-ext-* scripts and simplifies the installation of PHP extensions by automatically adding and removing Debian (apt) and Alpine (apk) packages. For example, to install the GD extension you simply have to run install-php-extensions gd. This tool is contributed by community members and is not included in the images, please refer to their Git repository for installation, usage, and issues.
I had similar issues in the past and resolved it by using install-php-extensions. See this comment.

Problem: Different encoding in two equal docker containers

Currently I have a very weird docker behavior and I really hope someone has an idea.
Here are some information about the setup:
My Dockerfile is based on php:7.4.27-apache-buster.
The container is build on two Kubernetes clusters (Staging and Productive).
The PHP application fetches data by a curl request two a third party system and tries to process this data and store it into a mariaDB database.
The mariaDB databases on staging and productive are equally setup.
The third party system responds with same data and encoding on both environments.
The weird behavior is, the staging container works as expected but the production container doesn't encode unicode characters properly.
Because both containers are build with the same Dockerfile, use the same application code, receive the same data and work with equally configured databases, I have no clue how this problem can be even possible. We also already tried to rebuild the container for both environments but nothing changed.
Did anybody experience something like that? Or has anybody any idea what the reason of this difference could be?
Application description:
The PHP application runs on a cron job. Every 15 minutes, a request is sent to a third party system, which response with a dataset in json format. This data is decoded processed by the application. While processing, the application checks for data validity and removes invalid data from the set. As a last step, the data is stored in the database.
MariaDB version:
Prod: 10.1.1
Dev: 10.5.17
PHP version: 7.4.27
Docker version: 20.10.18
Kubernetes version: 1.20.6
Go version: 1.18.6
Dockerfile:
FROM php:7.4.27-apache-buster
RUN curl -sL https://deb.nodesource.com/setup_17.x | bash -
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs
RUN apt-get remove -y libstdc++-8-dev && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
apt-get install -y fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf && \
apt-get install -y libx11-xcb1 libxtst6 libnss3 libxss1 libasound2 libatk-bridge2.0-0 libgtk-3-0 && \
apt-get install -y xvfb
RUN apt-get install -y cron sendmail && \
apt-get install -y libzip-dev && \
apt-get install -y chromium && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/*
RUN docker-php-ext-install pdo pdo_mysql mysqli zip
RUN apt-get update -y && apt-get install -y zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev imagemagick && \
docker-php-ext-configure gd --with-jpeg --with-freetype && \
docker-php-ext-install gd
COPY container/policy.xml /etc/ImageMagick-6/policy.xml
RUN apt-get update -y && \
apt-get install -y libmagickwand-dev && \
pecl install imagick && \
docker-php-ext-enable imagick
RUN groupadd -g 118 myapp
RUN useradd -d /myapp -G audio,video -g myapp -u 113 myapp
RUN chsh -s /bin/bash myapp
COPY --chown=myapp . .
COPY container/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod a+rx /usr/local/bin/entrypoint.sh
WORKDIR /app
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

build docker image with circleci/php:7.3-cli-node-browsers

I am trying to build an image in docker but after it compiles, I execute docker-compose up and it exits.
The docker file that I am using contains the next instructions:
FROM circleci/php:7.3-cli-node-browsers
USER root
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y \
libpng-dev \
zlib1g-dev \
zip \
curl \
&& docker-php-ext-install gd \
&& apt-get install -y zip \
&& apt-get install -y unzip \
&& apt-get install -y git \
&& apt install -y libsqlite3-dev zlib1g-dev \
&& docker-php-ext-install bcmath && docker-php-ext-enable bcmath \
&& docker-php-ext-install pcntl \
&& apt-get install -y --no-install-recommends libmagickwand-dev \
&& docker-php-ext-install exif \
&& pecl install imagick \
&& docker-php-ext-enable imagick
RUN pecl install redis && docker-php-ext-enable redis
COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
COPY / /var/www/html
RUN composer self-update
RUN composer install -n --prefer-dist
RUN npm install
RUN npm run test
RUN chmod -R 777 /var/www/html
RUN chmod -R o+w /var/www/html/storage
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
This a laravel project, with node and Redis. Any ideas why it is not working?
Thank in advance for your help.
Your entrypoint finally call apache, but you even did not install apache in your docker image.
So, you need do next:
Install apache2 in Dockerfile:
RUN apt-get install -y apache2
Correctly launch apache2 in docker-entrypoint.sh:
echo "--> Starting app"
. /etc/apache2/envvars
mkdir -p /var/run/apache2
exec apache2 -D FOREGROUND

Run Python Script from PHP Docker

I am running a Docker. Here is my docker file.
FROM php:5.6-apache
RUN apt-get update && apt-get install -my wget gnupg
RUN apt-key adv \
--keyserver hkp://keyserver.ubuntu.com:80 \
--recv 7F0CEB10
RUN echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list
RUN apt-get update
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libmcrypt-dev \
libssl-dev
RUN apt-get install -y libmariadbclient-dev
RUN docker-php-ext-install iconv mcrypt mysqli pdo_mysql mysql zip mbstring
RUN pecl install mongo
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer
RUN sed -i 's/^ServerSignature/#ServerSignature/g' /etc/apache2/conf-enabled/security.conf; \
sed -i 's/^ServerTokens/#ServerTokens/g' /etc/apache2/conf-enabled/security.conf; \
echo "ServerSignature Off" >> /etc/apache2/conf-enabled/security.conf; \
echo "ServerTokens Prod" >> /etc/apache2/conf-enabled/security.conf; \
a2enmod ssl; \
a2enmod headers; \
echo "SSLProtocol ALL -SSLv2 -SSLv3" >> /etc/apache2/apache2.conf
RUN apt-get install -y vim
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip3 install numpy
RUN pip3 install scipy
RUN pip3 install image_match
RUN pip3 install opencv-python
RUN pip3 install pytube
RUN pip3 install ez_setup
RUN pip3 install moviepy
RUN pip3 install requests
RUN pip3 install ffmpeg-python
RUN apt update && apt install -y libsm6 libxext6
RUN apt-get install -y libxrender-dev
RUN apt-get update
COPY config/mongo.ini /usr/local/etc/php/conf.d/
ENV VERSION 8
ENV UPDATE 91
ENV BUILD 14
In one my PHP Page, I want to Run a python script. for e.g.
$command = escapeshellcmd('python integrateFinal.py');
$joutput = shell_exec($command);
$output=json_decode($joutput);
The python script works fine with the command line as 'docker-compose exec web python3 integrateFinal.py'. It works and gives the output but when I run it from PHP page mentioned above It gives me error as permission denied.
So How should I run this PYTHON script?

Building a Docker image with deprecated dependencies

I am struggling to build a Docker image with Debian Wheezy, Apache 2.2, PHP 5 with mcrypt enabled. I want to use it to do some maintenance on a quirky, legacy prestashop application.
Most semi-automatic procedures include Apache 2.4 and that will not work. I would have thought that by now there would be an online tool to auto-generate Docker images to specifications.
How should I do it? Should I use Docker compose?
This is what I have so far. I am only missing how to start mysql and apache on image run.
FROM debian:wheezy
RUN apt-get update && \
apt-get install -y libmcrypt-dev \
subversion ssl-cert nano wget unzip && \
echo "deb http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list.d/dotdeb.list && \
echo "deb-src http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list.d/dotdeb.list && \
wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - && \
echo mysql-server-5.5 mysql-server/root_password password yourpass | debconf-set-selections && \
echo mysql-server-5.5 mysql-server/root_password_again password yourpass | debconf-set-selections && \
apt-get update && \
apt-get install -y \
apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 \
openssl php-pear php5 php5-cli php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-memcache php5-readline \
subversion ssl-cert nano wget unzip \
mysql-server-5.5 mysql-client mysql-client-5.5 mysql-common && \
/etc/init.d/mysql start && \
mysql -u root -pyourpass -e "create database mydb;" && \
rm -rf /var/lib/apt/lists/* && \
rm /etc/apache2/sites-enabled/000-default && \
mkdir -p /var/www/html && \
chown www-data:www-data -R /var/www/html/
COPY conf/etc/ /etc/
COPY mydump.sql /var/www/html/mydump.sql
RUN /etc/init.d/mysql start && \
mysql -u root -pyourpass -h localhost mydb < /var/www/html/mydump.sql && \
rm /var/www/html/mydump.sql
VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2", "/var/lib/mysql"]
EXPOSE 80 443 3306

Categories