php - Docker git not found in PATH
Get the solution ↓↓↓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?
Answer
Solution:
I believeCOPY --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
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: closed without sending a request; it was probably just an unused speculative preconnection
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.