How can I automatically run php-fpm command when I start the docker container?
I have this Dockerfile:
FROM composer:1.6.5 as build
WORKDIR /var/www
COPY . /var/www
RUN composer install
FROM php:7.2-fpm
USER root
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN apt-get update -y \
&& apt-get install -y nginx
RUN rm -rf /var/www/html
COPY --chown=www-data:www-data --from=build /var/www /var/www
COPY nginx.conf /etc/nginx/sites-enabled/default
EXPOSE 80
RUN service nginx restart
CMD ["nginx", "-g", "daemon off;"]
I know I should run php-fpm because when I access 127.0.0.1:8080 it doesn't show my webpage. But when I ssh into the container and run php-fpm then visit 127.0.0.1:8080 again it will show the webpage.
Should I add CMD ["php-fpm"] below? Is it okay to have two CMD in the Dockerfile?
It suggest that you create a start_service.sh script or whatever. to start both php_fpm and nginx when you start the container.
If the script its a good idea to both processes as daemons or in the background. And then just wait forever.
#!/bin/bash
"start php_fpm"
"start_iginx"
sleep infinite
In the CMD in the Dockerfile you just call your script instead of nginx.
Related
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
Hi i am new to docker.
I have cloned my laravel code from
https://github.com/laravel/laravel/tree/8.x
and followed the steps provided in given below link.
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
But still, mbstring is not installed in my project with php 8 version as my laravel project is compatible with a higher version than 7.2 but when i tried mbstring with 7.2 version it was easyly installed. i want to install mbstring with php 8 version.
Given below is my docker file. please have a look at it.
FROM php:8.0.3-fpm-buster
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
FROM php:8-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions mbstring pdo_mysql zip exif pcntl gd
#previous code
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
#RUN docker-php-ext-install
#RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
RUN php artisan key:generate
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
Try this..
What follows is more appropriate as a comment, but I have an insufficient reputation to comment.
Adarsh Hiwrale's excellent suggestion mostly worked for me, but I had to rearrange a few lines to avoid a race condition.
That is, the reordered lines are necessary for anyone starting from scratch who is building for the first time because they will not yet have a partial Docker build that can execute RUN php artisan key:generate.
My revision follows with comments indicating what was modified and why.
FROM php:8-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions mbstring pdo_mysql zip exif pcntl gd
#previous code
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
#RUN docker-php-ext-install
#RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# BEGIN MODIFICATIONS to Adarsh Hiwrate's suggested code
# Copy existing application directory contents
# The following line is redundant (predundant?) because of the line which copies the required items with the correct permissions.
# COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# This has to come after the above copy, otherwise the code will not yet be available in the container.
RUN php artisan key:generate
# END MODIFICATIONS to Adarsh Hiwrate's suggested code
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
I installed powershell in the php debian docker image and now I am installing PowerCLI module in the docker image to access the vsphere info and display using laravel. The issue is with the PowerCLI installation. Powershell doesn't seem to persist the modules installed and imported. When I import module and use RUN pwsh -c connect-viserver, it seems working in the docker-image. But when I call the cmdlet in laravel container as $process = new Process(['pwsh', '-c','Connect-VIServer', 'SERVERNAME']); it fails. I check to see if it is imported iin the powershell by accessing container docker exec -it app bash But the module is not installed. I am manually keeping the modules in a folder powershell/Modules and adding it to $env:$PSModulePath
I do not understand what I'm missing.
Here's is my docker file.
FROM php:7.4-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
RUN pwd
# Set working directory
WORKDIR /var/www
RUN pwd
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libonig-dev \
locales \
libzip-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
wget \
apt-utils
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl mysqli
RUN docker-php-ext-configure gd --enable-gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-enable mysqli
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
#########################
RUN pwd
# Download the Microsoft repository GPG keys
RUN wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
RUN dpkg -i packages-microsoft-prod.deb
# Update the list of products
RUN apt-get update
# Install PowerShell
RUN apt-get install -y powershell
# Start PowerShell
#RUN pwsh
# Allow installation from PSGallery
SHELL ["pwsh", "-command"]
RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
#RUN Install-Module VMware.VimAutomation.Core -Confirm:$false
#RUN Import-Module VMware.VimAutomation.Core; Get-Module
#RUN Set-PowerCLIConfiguration -ParticipateInCEIP $false -Confirm:$false
#RUN Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
##RUN connect-viserver 10.21.24.9
RUN Get-Module -ListAvailable VMware.VimAutomation.Core | Import-Module
RUN $env:PSModulePath = $env:PSModulePath + ":/var/www/powershell/Modules"
RUN mkdir -p /root/.config/powershell
RUN touch /root/.config/powershell/Microsoft.PowerShell_profile.ps1
RUN echo "Get-Module -ListAvailable PowerCLI* | Import-Module" >> /root/.config/powershell/Microsoft.PowerShell_profile.ps1
RUN $PSHome
RUN Get-Module
SHELL ["/bin/sh", "-c"]
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
RUN pwd
RUN ls -la && ls -la /var/www/powershell/Modules/
I have a need to combine the php:7.2 alpine with nginx in one dockerfile( in one docker image ) for production deployment of laravel app.
So I tried my way and I can only add nginx package. I can't find any nginx conf file in my image. I found many someone's images in docker hub. I tried a lot with this images and not working well.
Here is my docker file.
FROM php:7.2-alpine
RUN apk upgrade --update -q \
&& apk --no-cache -q add openssl zip unzip git mysql-client vim coreutils freetype-dev libpng-dev libjpeg-turbo-dev freetype libpng libjpeg-turbo libltdl libmcrypt-dev \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql opcache zip calendar \
&& apk del --no-cache -q freetype-dev libpng-dev libjpeg-turbo-dev
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apk --update add \
supervisor
RUN apk add --update nginx && rm -rf /var/cache/apk/*
RUN mkdir -p /tmp/nginx/client-body
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
#COPY website /usr/share/nginx/html
WORKDIR /var/www
COPY ./workspace-api /var/www
COPY ./workspace-api/supervisord.conf /etc/supervisord.conf
ADD ./workspace-api/root /etc/crontabs/
ADD ./workspace-api/php.ini /usr/local/etc/php
RUN composer install
RUN chmod -R 755 /var/www
RUN chmod +x /var/www/supervisor.sh
RUN /var/www/supervisor.sh
CMD ["nginx", "-g", "daemon off;"]
PS: I have docker-compose file for multi container app. But in this case, I only need to build all in one image for laravel.