Composer in php-fpm docker from composer:1.8.4 - php

I have a .dockerfile that builds a php-fpm image and I try to install composer from a docker image like so:
FROM php:7.3.3-fpm-alpine as base
WORKDIR /var/www
# Override Docker configuration: listen on Unix socket instead of TCP
RUN sed -i "s|listen = 9000|listen = /var/run/php/fpm.sock\nlisten.mode = 0666|" /usr/local/etc/php-fpm.d/zz-docker.conf
# Install dependencies
RUN set -xe \
&& apk add --no-cache bash icu-dev \
&& docker-php-ext-install pdo pdo_mysql intl pcntl
CMD ["php-fpm"]
FROM composer:1.8.4 as composer
RUN rm -rf /var/www && mkdir /var/www
WORKDIR /var/www
COPY composer.* /var/www/
ARG APP_ENV=dev
RUN set -xe \
&& if [ "$APP_ENV" = "prod" ]; then export ARGS="--no-dev"; fi \
&& composer install --prefer-dist --no-scripts --no-progress --no-suggesthere
The problem is that the COPY composer.* /var/www/ does not seem to work properly because it throws the error:
composer install --prefer-dist --no-scripts --no-progress --no-suggest --no-interaction --no-dev
Composer could not find a composer.json file in /var/www
It seems like either the composer image is missing something or I skip some step, could you please assist, I am both new to docker and php.

Problem in the
WORKDIR /var/www
The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile.
Any RUN, CMD, ADD, COPY, or ENTRYPOINT command will be executed in the
specified working directory.
Source: https://www.educative.io/edpresso/what-is-the-workdir-command-in-docker

Related

Php-fpm alpine can't resolve gitlab on my domain

I wrote myself a dockerfile that puts an application in Symfony. Unfortunately, the problem is that using the php:7.4.9-fpm-buster image everything works, but when php:7.4-fpm-alpine works it is a problem with the host service.
On alpine I get an error when installing composer:
#0 0.284 ssh: Could not resolve hostname gitlab.pawel.com: Name does not resolve
#0 0.284 fatal: Could not read from remote repository.
#0 0.284 Please make sure you have the correct access rights
#0 0.284 and the repository exists.
I already tried adding to /etc/hosts
193.33.111.185 gitlab.pawel.com
I also tried this /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
I need a working image for alpine, but I have no idea what the problem is. This i my all code
FROM php:7.4-fpm-alpine
ARG ABSOLUTE_PATH=./app
ARG CONFIG_PATH=./config/web_adapter
RUN apk update && apk add openssh-client
#COPY CONFIG
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY $CONFIG_PATH/conf.d/api-platform.ini $PHP_INI_DIR/conf.d/api-platform.ini
COPY $CONFIG_PATH/www.conf /usr/local/etc/php-fpm.d/www.conf
RUN adduser -D app
WORKDIR /srv
COPY $ABSOLUTE_PATH/composer.json $ABSOLUTE_PATH/composer.lock $ABSOLUTE_PATH/symfony.lock ./
RUN set -eux; \
composer update symfony/flex --no-plugins --no-scripts; \
composer install --prefer-dist --no-autoloader --no-scripts --no-progress --no-suggest; \
composer clear-cache
COPY $ABSOLUTE_PATH/bin bin/
COPY $ABSOLUTE_PATH/config config/
COPY $ABSOLUTE_PATH/public public/
COPY $ABSOLUTE_PATH/src src/
RUN mkdir -p var/cache var/log var/cache/prod
RUN chown -R app:app /srv
RUN set -eux; \
mkdir -p var/cache var/log; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync
#ENTRYPOINT
COPY $CONFIG_PATH/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
USER app
ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]
Of course IP and domain name is only as a example. Any idea what I did wrong?

000-default.conf not found while building docker image of Laravel app on windows

I am trying to deploy my Laravel application on AWS using docker image by following given tutorial:
https://medium.com/#okekedesmond/deploying-containerized-laravel-application-using-aws-ec2-instances-with-docker-and-rds-883e8f6d6245
I am stuck at first point while building docker image. Here is my Dockerfile:
# Defining the base image for our project, if you understand how docker images and layers work, this should not be difficult to understand.
FROM php:7.3-cli
# We need to update the image and install some import packages
RUN apt-get update -y && apt-get install -y openssl zip unzip git curl libpng-dev libonig-dev libxml2-dev
# cleaning packages and install scripts
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Installing composer which is used to install Laravel
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin –filename=composer
#Creating a configuration file for apache and linking
ADD 000-default.conf /etc/apache2/sites-available/
RUN ln -sf /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf
#Restarting Apache
RUN a2enmod rewrite
RUN service apache2 restart
# Create a work directory and copy all project file into the
WORKDIR /var/www/app/
COPY . /var/www/app
#Granting permissions to files and folders
RUN chmod -R o+w /var/www/app/storage
RUN chown -R www-data:www-data ./storage
RUN chgrp -R www-data storage bootstrap/cache
RUN chmod -R ug+rwx storage bootstrap/cache
RUN chmod -R 755 /var/www/app/
RUN find /var/www/app/ -type d -exec chmod 775 {} \;
RUN chown -R www-data:www-data /var/www
# Installing dependencies from laravel package
RUN composer install --no-scripts --no-autoloader --no-ansi --no-interaction --working-dir=/var/www/app
#Running some packages
RUN docker-php-ext-install mbstring pdo pdo_mysql mbstring exif pcntl bcmath gd opcache
#Running Laravel on docker, because we are using the php-7.3-cli so we have to use a php server in our docker image
CMD php artisan serve --host=0.0.0.0 --port=80
EXPOSE 80`
It is giving error at step no. 5:
Step 5/21 : ADD 000-default.conf /etc/apache2/sites-available/
ADD failed: file not found in build context or excluded by .dockerignore: stat 000-default.conf: file does not exist
How do I solve it on windows? any help will be appreciated
I think the best solution is to manually make a new one, here is an example file:
https://gist.github.com/tjtoml/942d696c868b22a25259
And it should be located in:
/etc/apache2/sites-available/000-default.conf
It could be that you have to customize it for your needs

custom make install in Docker file

Not able to run make install from docker file, not sure where I am going wrong.
Getting below error message when docker-compose build is run in ubuntu
Step 6/10 : RUN make install
---> Running in c8f67e8de3b5
make: *** No rule to make target 'install'. Stop.
ERROR: Service 'web' failed to build:
The command '/bin/sh -c make install' returned a non-zero code: 2
I have the below structure where server is laravel project and in root there is a docker-compose.yml file.
Below is the structure of server folder
docker-compose.yml file
version: '3'
services:
web:
image: api_server
container_name: api_server
build:
context: ./server/release
ports:
- 9000:80
volumes:
- ./server:/var/www/app
Dockerfile
FROM php:7.3.1-apache-stretch
RUN apt-get update -yqq && \
apt-get install -y apt-utils zip unzip && \
apt-get install -y nano && \
apt-get install -y libzip-dev libpq-dev libpng-dev&& \
a2enmod rewrite && \
docker-php-ext-install gd mbstring && \
docker-php-ext-install pdo_pgsql && \
docker-php-ext-install pgsql && \
docker-php-ext-configure zip --with-libzip && \
docker-php-ext-install zip && \
rm -rf /var/lib/apt/lists/*
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
COPY default.conf /etc/apache2/sites-enabled/000-default.conf
WORKDIR /var/www/app
RUN make install
RUN chown -R www-data:www-data /var/www/app/
RUN chmod -R 777 /var/www/app/storage
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
EXPOSE 80
server/Makefile
install:
# some other commands
composer install
refresh:
# For testing
php artisan migrate:refresh
php artisan db:seed
make run:
php artisan migrate:status
php artisan serve
Basically if I comment RUN make install and RUN chmod -R 777 /var/www/app/storage commands from Dockerfile it works. To test i'll get into the container and run the above 2 commands manually then it works by showing the default laravel page.
So I feel trying to run the above 2 commands from Dockerfile i guess source code isn't available at that point.

Docker stack and Doctrine migration

I have a simple docker stack with three containers : a mysql one, a php-fpm one and a nginx.
I just want to be able to execute my doctrine migrations and a symfony command every time my container is created.
Currently, i got an error like : "entrypoint.sh not found" when i type docker logs #myphpcontainername# after building and docker-compose up -d 'ing.
My php-fpm docker file :
FROM php:7.2-fpm
RUN apt-get update
RUN apt-get install -y zlib1g-dev libpq-dev git libicu-dev libxml2-dev \
......
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
WORKDIR /var/www/symfony
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ['/entrypoint.sh']
And my entrypoint.sh, located at the same place than my Dockerfile :
#!/bin/bash
set -e
sleep 5
php /var/www/symfony/bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
exec "$#"
I believe you will need to make that file executable
RUN chmod 0700 entrypoint.sh
or it should be
ENTRYPOINT /entrypoint.sh
Take a look at this post that has a good explanation
https://www.ctl.io/developers/blog/post/dockerfile-entrypoint-vs-cmd/
Try this
ADD . /var/www/symfony
WORKDIR /var/www/symfony
RUN chmod +x entrypoint.sh
...
CMD ["/var/www/symfony/entrypoint.sh"]

Permission Issue in Docker container for Symfony2

I'm tring to create an Docker image to bootstrap Symfony project.
Here is my Dockerfile:
FROM php:7-apache
LABEL Description = "This image is used to start Symfony3 project"
ENV DIRPATH /var/www/html
# apt-get command
RUN apt-get update && apt-get install -y \
vim \
git
RUN apt-get install -y zlib1g-dev && docker-php-ext-install zip
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Install the Symfony Installer
RUN curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
RUN chmod a+x /usr/local/bin/symfony
# Create the php.ini file
RUN cp /usr/src/php/php.ini-development /usr/local/etc/php/php.ini
The build and the container creation works well but I have a permission issue in my container.
When I'm going to my app_dev.php, I have this message:
You are not allowed to access this file. Check app_dev.php for more information.
Apparently, I can access this file only with localhost.
Also, PHP can't delete or create anything in my container.
For exemple I have the following error when I'm running:
$php app/console cache:clear
Failed to remove directory "/var/www/html/app/cache/dev_old/doctrine
How can I solved that in my Dockerfile?
Finally found it after weeks:
Add that in you Dockerfile. It solved the permission issue.
# Workaround for write permission on write to MacOS X volumes
# See https://github.com/boot2docker/boot2docker/pull/534
RUN usermod -u 1000 www-data

Categories