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?
Related
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
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
I have a build plan in Atlassian Bamboo that builds a Docker image of a PHP project. The image includes Apache2, PHP and dependencies, and of course the project itself. When I try to run the Docker image generated by this build plan, I get a permission denied error to the project.
I am using root as the primary user in the Docker container. I also tried to include a chown command in the Dockerfile for www-data:www-data for the PHP project directory but the problem did not go away.
This is what happens to the permission of the indicated file:
--w------- 1 root root 582 Feb 18 12:17 index.php
The contents of the Dockerfile
FROM php:apache
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && ln -fs /usr/share/zoneinfo/Asia/Manila /etc/localtime \
&& apt-get install -y libzip-dev libpng-dev unzip git tzdata libpq-dev && dpkg-reconfigure --frontend noninteractive tzdata \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo_pgsql pgsql zip gd \
&& rm -rf /var/lib/apt
WORKDIR /var/www/html
COPY composer.json .
COPY composer.lock .
COPY composer.phar .
RUN php composer.phar install
RUN chmod 775 -R /var/www/html
COPY . .
I came across this post indicating that the problem was an internal change in Atlassian Bamboo. What I did then was to use 771 as the permission for all the files in the PHP project and changed the ownership as well through chown. This combination was the correct one apparently and allowed the application to run.
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"]
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