Docker git not found in PATH - php

I'm still learning docker, and i'm trying to Dockerize a laravel project.
I'm trying to execute laravel composer in docker, however git does not work:
[RuntimeException] git was not found in your PATH, skipping source download
Git works normal in my local machine.
My Docker file:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql sockets
RUN curl -sS https://getcomposer.org/installer​ | php -- \
--install-dir=/usr/local/bin --filename=composer~
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /app
COPY . .
RUN composer install
I've tried to install git using dockerfile:
FROM alpine
RUN apk add --no-cache git
CMD ["git","--version"]
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
but docker build dont work:
=> ERROR [stage-0 8/8] RUN apt-get update && apt-get upgrade -y && apt-get install -y git
docker-compose.yml:
version: '3.8'
services:
php-apache-environment:
container_name: php-apache.
image: php:7.4-apache
volumes:
- ./:/var/www/html
ports:
- 8001:80
How git works in docker? I have to change my environment variables somehow or can i install git on docker?
Or perhaps both and i doing both wrong?

I believe COPY --from=composer:2.0 /usr/bin/composer /usr/bin/composer is sufficient to install composer in you docker project .
I created a dockerfile for a laravel project before and this is how it looked
FROM php:7.3-apache
# 1. development packages
RUN apt-get update && apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libzip-dev \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
g++
# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
mbstring \
pdo_mysql \
zip
#upload
RUN echo "file_uploads = On\n" \
"memory_limit = 500M\n" \
"upload_max_filesize = 500M\n" \
"post_max_size = 500M\n" \
"max_execution_time = 600\n" \
> /usr/local/etc/php/conf.d/uploads.ini
# 5. composer
COPY --from=composer:2.0 /usr/bin/composer /usr/bin/composer

Related

"deploy-php-ext-configure" in /bin/sh missing when building docker laravel image

i am trying to build image and container from a project but i am having an issue when trying to build the image. the project is a template and I already have a project using this template in my computer. I would like to know how to solve it and understand a little more. I hope somebody would help me.
here is the error log when I run the command "docker build -t my-payments ." :
#7 200.3 /bin/sh: 1: deploy-php-ext-configure: not found
here is the "docker-compose.yml" :
version: '3.8'
services:
web:
container_name: laravel-template-...
build:
context: ./
dockerfile: ./Dockerfile.dev
volumes:
- .:/var/www-data
environment:
- PORT=80
ports:
- 81:80
links:
- db
db:
image: postgres:13
container_name: db-lrv-postgres-...
restart: always
environment:
POSTGRES_DB: db-lrv-postgres
POSTGRES_USER: ...
POSTGRES_PASSWORD: ...
TZ: ...
PORT: ${PORT:-5432}
ports:
- "5434:5432"
here is "Dockerfile" :
FROM php:7.4-fpm
USER root
WORKDIR /var/www-data
RUN apt-get update \
# gd
&& apt-get install -y --no-install-recommends build-essential openssl nginx libfreetype6-dev libjpeg-dev libpng-dev libwebp-dev zlib1g-dev libzip-dev gcc g++ make nano vim unzip curl git jpegoptim optipng pngquant gifsicle locales libonig-dev nodejs npm libpq-dev \
#custom-dependencies installed: libpq-dev
&& deploy-php-ext-configure gd \
&& deploy-php-ext-install gd \
# gmp
&& apt-get install -y --no-install-recommends libgmp-dev \
&& deploy-php-ext-install gmp \
# pdo
&& deploy-php-ext-install pdo \
# pdo_pgsql
&& deploy-php-ext-install pgsql pdo_pgsql mbstring \
# opcache
&& deploy-php-ext-enable opcache \
# zip
&& deploy-php-ext-install zip \
&& apt-get autoclean -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/pear/
COPY . /var/www-data
COPY ./deploy/php.ini /usr/local/etc/php/conf.d/local.ini
COPY ./deploy/nginx.conf /etc/nginx/nginx.conf
RUN mv .env.production .env
RUN chmod +rwx /var/www-data
RUN chmod -R 777 /var/www-data
#RUN npm install -g npm#latest
RUN npm install
RUN npm run prod
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer install --working-dir="/var/www-data"
RUN composer dump-autoload --working-dir="/var/www-data"
RUN php artisan optimize
EXPOSE 8080
RUN ["chmod", "+x", "./deploy/post_deploy.sh"]
CMD [ "sh", "./deploy/post_deploy.sh" ]

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

Can not find autoload.php when running laravel in a docker container

I am trying to run laravel on a docker container. However, I created a docker file to install the required dependencies and extensions. Then, I created a docker-compose file to run the container. But, when running the container using docker-compose up the following error appears:
Warning: require(/var/www/vendor/autoload.php): failed to open stream:
No such file or directory in /var/www/artisan on line 18 main_system_1
| main_system_1 | Fatal error: require(): Failed opening required
'/var/www/vendor/autoload.php' (include_path='.:/usr/local/lib/php')
in /var/www/artisan on line 18 workspace_main_system_1 exited with
code 255
The Dockerfile:
FROM php:alpine
# Install dev dependencies
RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
curl-dev \
imagemagick-dev \
libtool \
libxml2-dev \
postgresql-dev \
sqlite-dev
# Install production dependencies
RUN apk add --no-cache \
bash \
curl \
g++ \
gcc \
git \
imagemagick \
libc-dev \
libpng-dev \
make \
mysql-client \
nodejs \
nodejs-npm \
yarn \
openssh-client \
postgresql-libs \
rsync \
zlib-dev \
libzip-dev
# Install PECL and PEAR extensions
RUN pecl install \
imagick
# Install and enable php extensions
RUN docker-php-ext-enable \
imagick
RUN docker-php-ext-configure zip --with-libzip
RUN docker-php-ext-install \
curl \
iconv \
mbstring \
pdo \
pdo_mysql \
pdo_pgsql \
pdo_sqlite \
pcntl \
tokenizer \
xml \
gd \
zip \
bcmath
# Install composer
ENV COMPOSER_HOME /composer
ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
# Install PHP_CodeSniffer
RUN composer global require "squizlabs/php_codesniffer=*"
# Cleanup dev dependencies
RUN apk del -f .build-deps
# Setup working directory
WORKDIR /var/www
COPY composer.json composer.json
#COPY composer.lock composer.lock
RUN composer install --no-autoloader
COPY . .
RUN composer dump-autoload
RUN php artisan key:generate
RUN php artisan jwt:secret
RUN chmod 777 -R storage
CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000
And this is my docker-composr.yml file:
ersion: '3.1'
services:
main_system:
build: ./main-system
ports:
- 8000:8000
env_file: ./main-system/.env
volumes:
- ./main-system:/var/www
Your dockerfile runs composer install --no-autoloader. This may be the issue.
I solved the problem by:
removing the volume from docker-compose.yml
change the order of the COPY . . command and put it before RUN composer install
removing the --no-autoloader

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