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"]
Related
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.
I was using a docker container with php:8.1.6-cli and running my laravel aplication.
When i attach the terminal to the container and run a simple command php artisan inspire the docker takes 8 seconds to execute.
My php.ini config:
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Sao_Paulo
My Dockerfile for this container:
FROM php:8.1.6-cli
LABEL maintainer="Crazynds"
WORKDIR /workspace
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC-3
ENV NODE_VERSION=16
USER root
RUN apt-get update \
&& apt-get install -y libcurl4-openssl-dev libonig-dev libzip-dev libpq-dev build-essential gnupg gosu curl zip unzip git supervisor libcap2-bin libpng-dev python2 locales \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -
RUN apt-get install -y nodejs nano wget dos2unix
RUN apt-get -y autoremove \
&& apt-get clean\
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pecl install redis && docker-php-ext-enable redis; exit 0
RUN docker-php-ext-install pdo_mysql pdo_pgsql mbstring exif pcntl curl zip gd
ENTRYPOINT ["sleep","infinity"]
How i find the problem that takes most of the time to execute the php comands?
Is there any way to check what is consuming each part of time in the execution?
I find the solution. The docker with volumes mounted using Windows dirs are slow.
The solution for my problem is to create the vendor folder and the node_modules in separated volumes, instead of mounting them from Windows folder.
That alone gave a big performance boost, now the response time is around 1 second, but if I mounted my entire project on the volume instead of a folder, it would be much faster.
I always used GD to manipulate webp normally in my local environment, but when attempting to test my scripts in docker environment, i get "Webp format is not supported by PHP installation." error. I am using latest php version as in showed in my dockerfile below:
FROM php:8-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
pngquant
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
# php.ini
COPY ./docker-compose/php/php.ini /usr/local/etc/php/
What i am missing?
You need to install libwebp-dev and configure gd lib to support it:
RUN apt-get update && ... \
apt-get install -y libwebp-dev && \
docker-php-ext-configure gd --with-webp;
The the examples here : https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions
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
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/