Convert circleci into docker file - php

I am new to creating containers in docker and I am trying to create my docker-compose for a project laravel(Php)l I have. I have the following .circleci and I want to convert it into a docker container. Anyone who can help me?
version: 2
jobs:
build:
docker:
- image: circleci/php:7.3-node-browsers
working_directory: ~/laravel-boilerplate
steps:
- checkout
- run: sudo apt install -y libsqlite3-dev zlib1g-dev
- run: sudo docker-php-ext-install zip
- run: sudo apt-get install -y libpng-dev
- run: sudo docker-php-ext-install gd
- run: sudo docker-php-ext-install bcmath && sudo docker-php-ext-enable bcmath
- run: sudo docker-php-ext-install pcntl
- run: sudo apt-get install -y --no-install-recommends libmagickwand-dev
- run: sudo docker-php-ext-install exif
- run: sudo pecl install imagick
- run: sudo docker-php-ext-enable imagick
- run: sudo composer self-update
- restore_cache:
keys:
- composer-v1-{{ checksum "composer.lock" }}
- composer-v1-
- run: composer install -n --prefer-dist
- save_cache:
key: composer-v1-{{ checksum "composer.lock" }}
paths:
- vendor
- restore_cache:
keys:
- node-v1-{{ checksum "package.json" }}
- node-v1-
- run: npm install
- save_cache:
key: node-v1-{{ checksum "package.json" }}
paths:
- node_modules
- run: npm run test
- run: npm run production
- run: cp .env.example .env
- run: php artisan key:generate
- run: ./vendor/bin/phpunit
I have built a docker file but it doesn't work. This is the code of the of it:
FROM circleci/php:7.3-cli-node-browsers
USER root
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=866729
WORKDIR /var/www/html
#RUN apt-get update
#RUN apt-get install -y apt-utils
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
#ENV APACHE_RUN_DIR /var/lib/apache/runtime
#RUN mkdir -p ${APACHE_RUN_DIR}
RUN apt-get install -y apache2
#####################################
# PHPRedis:
#####################################
RUN pecl install redis && docker-php-ext-enable redis
# moving the file that manages the host url
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
#COPY package.json /tmp/package.json
#RUN cd /tmp && npm install
#RUN mkdir -p /var/www/html && cp -a /tmp/node_modules /var/www/html/
# From here we load our application's code in, therefore the previous docker
# "layer" thats been cached will be used if possible
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 npm run production
#RUN chmod -R 775 /var/www/html
#RUN chown -R www-data:www-data /var/www/html
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 rm -f /usr/local/bin/docker-entrypoint.sh
#RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]

Why are you trying to use composer inside a docker image? Docker-compose.yml is an external add-on over Dockerfile. Composer helps automate the use of existing (or built new) docker images when creating projects or services.

Related

running composer install in Dockerfile

I am trying to dockerize a PHP laravel app. I am using a PHP and a composer image to achieve this. However, when I run composer install, I get all my packages installed but then run into this error:
/app/vendor does not exist and could not be created.
I want composer to create the /vendor directory! Could this be a permission issue?
Here is my Dockerfile:
FROM php:7.4.3-cli
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# 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
COPY --from=composer:2.4.4 /usr/bin/composer /usr/local/bin/composer
# Set working directory
WORKDIR /app
COPY . .
# Add a new user "john" with user id 8877
RUN useradd -u 8877 john
# Change to non-root privilege
USER john
RUN composer install
I created a user with an arbitrary ID since it's a bad practice to run composer install as root security-wise.
I was able to solve the problem by making some changes to my Dockerfile:
FROM php:7.4.3-cli
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# 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
COPY --from=composer:2.4.4 /usr/bin/composer /usr/local/bin/composer
# Add a new user "john" with user id 8877
RUN useradd -u 8877 john
# Set working directory
WORKDIR /app
COPY . .
RUN chmod -R 775 /app
RUN chown -R john:john /app
# Change to non-root privilege
USER john
RUN composer install --no-scripts --no-plugins

PHP GD no webp support in docker

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

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

While running docker build it can't read /etc/php/7.2/apache2/php.ini: No such file or directory

While i am building the docker file i am getting the error that can't read /etc/php/7.2/apache2/php.ini: No such file or directory but in the local path file was available.
I need to know how to give the access to the file which is available in my local.
No such file or directory Error image
My DOCKERfile
FROM ubuntu:16.04
MAINTAINER Sreekanth G S <mail#sreekanth.in>
#ENV http_proxy=http://sysfp0t.its.unc.edu:80
#ENV https_proxy=http://sysfp0t.its.unc.edu:80
#RUN DEBIAN_FRONTEND=noninteractive \
# apt-get -o Acquire::http::Proxy="http://sysfp0t.its.unc.edu:80" update && \
# apt-get -o Acquire::http::Proxy="http://sysfp0t.its.unc.edu:80" install -y language-pack-en-base &&\
# export LC_ALL=en_US.UTF-8 && \
#` export LANG=en_US.UTF-8
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y software-properties-common
#RUN cat /etc/locale.gen
#RUN cat /etc/environment
#RUN LANG=en_US.UTF-8 locale-gen --purge en_US.UTF-8 && echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && echo "LC_ALL=en_US.UTF-8" > /etc/environment && echo "LANG=en_US.UTF-8" >> /etc/environment && locale-gen "en_US.UTF-8" && export LC_ALL=en_US.UTF-8 && export LANG=en_US.UTF-8 && add-apt-repository ppa:ondrej/php
#RUN apt-get -o Acquire::http::Proxy="http://sysfp0t.its.unc.edu:80" update && apt-get -o Acquire::http::Proxy="http://sysfp0t.its.unc.edu:80" install -y software-properties-common language-pack-en-base && \
#LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php && apt-get -o Acquire::http::Proxy="http://sysfp0t.its.unc.edu:80" update && apt-get -o Acquire::http::Proxy="http://sysfp0t.its.unc.edu:80" install -y \
RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu xenial main" >> /etc/apt/sources.list && echo "deb-src http://ppa.launchpad.net/ondrej/php/ubuntu xenial main" >> /etc/apt/sourceis.list && apt-get update --allow-unauthenticated
RUN cat /etc/apt/sources.list && ls -l /etc/apt/
RUN apt-get install -y --allow-unauthenticated apache2-bin libapache2-mod-php php-curl php-ldap php-mysql php-mcrypt \
php-gd php-xml patch curl vim git mysql-client wget unzip
RUN phpenmod mcrypt && phpenmod gd
RUN a2enmod xml2enc && a2enmod rewrite
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.2/apache2/php.ini
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.2/cli/php.ini
RUN useradd --uid 1000 --gid 50 docker
RUN echo export APACHE_RUN_USER=docker >> /etc/apache2/envvars
RUN echo export APACHE_RUN_GROUP=staff >> /etc/apache2/envvars
COPY 000-default.conf /etc/apache2/sites-enabled/000-default.conf
RUN chown -R docker /var/www/html
WORKDIR /var/www/html
RUN wget -q "http://www.sentrifugo.com/home/downloadfile?file_name=Sentrifugo.zip" -O Sentrifugo.zip
#COPY Sentrifugo.zip /var/www/html/
RUN unzip Sentrifugo.zip && mv Sentrifugo_3.2 sentrifugo
WORKDIR /var/www/html/sentrifugo
RUN chown -R docker .
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chmod 777 -R public/downloads public/uploads public/email_constants.php \
public/emptabconfigure.php \
public/site_constants.php \
public/db_constants.php \
public/application_constants.php \
public/mail_settings_constants.php \
logs/application.log \
application/modules/default/plugins/AccessControl.php \
install
VOLUME /var/www/html/sentrifugo/public/uploads
VOLUME /var/www/html/sentrifugo/public/downloads
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 80
docker-compose.yml file
version: '3'
services:
sentrifugo:
build:
context: .
dockerfile: Dockerfile-sentrifugo
container_name: sentrifugo
ports:
- "8080:80"
- "8443:443"
devices:
- "/dev/tty:/dev/tty"
links:
- "mariadb:mariadb"
mariadb:
build:
context: .
dockerfile: Dockerfile-mariadb
container_name: mariadb
ports:
- "3306:3306"
Dockerfile-mariadb
from mariadb:latest
ENV MYSQL_RANDOM_ROOT_PASSWORD=true
ENV MYSQL_DATABASE=sentrifugo
ENV MYSQL_USER=sentrifugo
ENV MYSQL_PASSWORD=54y6RxN7GfC7aes3
EXPOSE 3306
My local folder Image
My local drive path and file details
Command to build the script
docker-compose up -d
DOCKER FILE
FROM ubuntu:trusty
MAINTAINER Oleksandr Simonov <asimonov#gmail.com>
RUN apt-get update && apt-get install -y \
apache2-bin \
libapache2-mod-php5 \
php5-curl \
php5-ldap \
php5-mysql \
php5-mcrypt \
php5-gd \
patch \
curl \
vim \
git \
mysql-client
RUN php5enmod mcrypt
RUN php5enmod gd
RUN a2enmod rewrite
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php5/apache2/php.ini
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php5/cli/php.ini
RUN useradd --uid 1000 --gid 50 docker
RUN echo export APACHE_RUN_USER=docker >> /etc/apache2/envvars
RUN echo export APACHE_RUN_GROUP=staff >> /etc/apache2/envvars
COPY 000-default.conf /etc/apache2/sites-enabled/000-default.conf
COPY . /var/www/html
RUN chown -R docker /var/www/html
WORKDIR /var/www/html
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 80
It works for me error solved.

Docker install PHP-7-fpm with Memcache extention ? fails with Cannot find config.m4

I am trying install Docker with PHP version 7.0 with memcache support, my docker-file is as below, however it fails #STEP 10 with error
Step 10 : RUN /usr/bin/phpize
---> Running in 450678a59cd4
Cannot find config.m4.
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
[31mERROR[0m: Service 'php' failed to build: The command '/bin/sh -c /usr/bin/phpize' returned a non-zero code: 1
Docker file is as below
FROM php:7.0-fpm
#FROM php:5.6-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install mysqli mbstring pdo_mysql
# Download and Installing php libraries
RUN apt-get -y install php-pear php5-dev
# Download and Installing git and vim
RUN apt-get -y install git vim gcc
# Download and Installing zip unzip
RUN apt-get -y install zip unzip
# install PHP PEAR extensions
RUN apt-get -y install wget
#RUN wget http://pecl.php.net/get/memcache-3.0.9-dev.tgz && gunzip memcache-3.0.9-dev.tgz && tar -xvf memcache-3.0.9-dev.tar && cd memcache-3.0.9-dev \
# && phpize && ./configure && make && make install
# RUN git clone https://github.com/websupport-sk/pecl-memcache && cd pecl-memcache
RUN apt-get -y install libmemcached-dev libmemcached11
RUN git clone https://github.com/php-memcached-dev/php-memcached && cd php-memcached && git checkout -b php7 origin/php7
RUN /usr/bin/phpize
RUN ./configure && make && make install
RUN apt-get install -y memcached
EXPOSE 9000
COPY ./www.conf /etc/php-fpm.d/www.conf
COPY ./php.ini /etc/php.ini
COPY ./php-fpm.conf /etc/php-fpm.conf
COPY ./40-memcache.ini /etc/php.d/40-memcache.ini
#COPY bootstrap.sh /opt/bootstrap.sh
#RUN chmod +x /opt/bootstrap.sh
#ENTRYPOINT ["/opt/bootstrap.sh"]
Here's how your Dockerfiles should look like:
PHP-FPM Dockerfile:
FROM php:7.0-fpm
# ...
RUN apt-get update && apt-get install -y \
libpq-dev \
libmemcached-dev \
curl
# ...
# Install Memcached for php 7
RUN curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-memcached/archive/php7.tar.gz" \
&& mkdir -p /usr/src/php/ext/memcached \
&& tar -C /usr/src/php/ext/memcached -zxvf /tmp/memcached.tar.gz --strip 1 \
&& docker-php-ext-configure memcached \
&& docker-php-ext-install memcached \
&& rm /tmp/memcached.tar.gz
# ...
CMD ["php-fpm"]
EXPOSE 9000
Memcached Dockerfile:
FROM memcached:latest
CMD ["memcached"]
EXPOSE 11211
This is taken from https://github.com/LaraDock/laradock
You need to run that command /usr/bin/phpize in the right folder.
See this Dockerfile as an example
RUN wget https://github.com/phpredis/phpredis/archive/2.2.5.zip; unzip 2.2.5.zip
WORKDIR /tmp/php-redis/phpredis-2.2.5
RUN /usr/bin/phpize; ./configure; make; make install
In your case, you did clone the repo php-memcached and make a cd in it, but that does not change the working directory for the next Dockerfile RUN directive.
Set that working directory before the RUN directive:
WORKDIR /php-memcached
RUN /usr/bin/phpize
This work for me:
FROM php:7.1.1-fpm
RUN apt-get update
RUN docker-php-ext-install mysqli
RUN apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN apt-get install git -y
RUN git --version
RUN apt-get install -y build-essential libmemcached-dev
RUN git clone https://github.com/php-memcached-dev/php-memcached.git
RUN cd php-memcached \
&& git checkout php7 \
&& phpize \
&& ./configure --disable-memcached-sasl \
&& make \
&& make install

Categories