I have a Dockerfile in my project
FROM php:7.4-fpm-alpine
WORKDIR '/app'
RUN set -ex \
&& apk update && apk upgrade\
# Installations into virtual env so they can be deleted afterwards
# (.phpize-deps is standardized by docker-php-ext-install)
&& apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \
&& apk add --no-cache --virtual .build-deps \
postgresql-dev \
libstdc++ \
make \
# Installations that should be kept
&& apk add --no-cache \
bash \
wget \
curl \
libbz2 \
libzip-dev \
zlib-dev \
bzip2-dev \
libxslt-dev \
libmcrypt-dev \
libxml2-dev \
libjpeg-turbo-dev \
libpng-dev \
yaml-dev \
libaio-dev \
oniguruma-dev \
php7-bz2 \
php7-pdo php7-pgsql php7-bcmath php7-zmq php7-curl php7-pear \
# unzip \
# ffmpeg \
# Install php extensions
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install bcmath bz2 exif gd json mbstring opcache pcntl pdo pdo_pgsql simplexml sockets xsl zip \
&& pecl install apcu-5.1.18 \
&& docker-php-ext-enable apcu \
# Install composer
&& EXPECTED_COMPOSER_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig) \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '${EXPECTED_COMPOSER_SIGNATURE}') { echo 'Composer.phar Installer verified'; } else { echo 'Composer.phar Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/bin --filename=composer \
&& php -r "unlink('composer-setup.php');" \
# Remove unnecessary stuff
&& apk del .phpize-deps .build-deps
# install xdebug
#RUN pecl install xdebug
#RUN wget http://xdebug.org/files/xdebug-2.6.1.tgz
#RUN tar -xvzf xdebug-2.6.1.tgz
#RUN cd xdebug-2.6.1 \
#&& phpize \
#&& ./configure --enable-xdebug \
#&& make \
#&& make install \
#&& cp modules/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718 \
#&& echo 'zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so' >> /usr/local/etc/php/php.ini \
#&& echo 'zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so' >> /etc/php7/php.ini \
#&& echo 'xdebug.remote_enable=true' >> /etc/php7/php.ini \
#&& echo 'xdebug.remote_host=127.0.0.1' >> /etc/php7/php.ini \
#&& echo 'xdebug.remote_port=9000' >> /etc/php7/php.ini \
#&& echo 'xdebug.remote_handler=dbgp' >> /etc/php7/php.ini \
#&& echo 'xdebug.max_nesting_level=512' >> /etc/php7/php.ini
#EXPOSE 22
# Install PDO_PGSQL and APCU
#RUN set -ex \
# && apk --no-cache add \
# postgresql-dev \
# libpq-dev \
# && docker-php-source extract \
# && apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \
# && pecl install apcu-5.1.12 \
# && docker-php-ext-enable apcu \
# && docker-php-ext-install pdo pdo_pgsql \
# && apk del .phpize-deps
# && docker-php-source delete
WORKDIR /var/www/html
# Use the default PHP production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
# custom PHP adjustments
COPY .server/config/php.ini $PHP_INI_DIR/conf.d/zz-usln.ini
# custom PHP-FPM adjustments (zz to make them the last being applied)
COPY .server/config/php-fpm.conf ${PHP_INI_DIR}-fpm.d/zz-usln.conf
RUN sed -ie 's/;daemonize = yes/daemonize = no/g' ${PHP_INI_DIR}-fpm.d/zz-usln.conf
# RUN echo $(locate php-fpm.conf)
# Composer install stuff
COPY composer.* ./
RUN set -ex \
&& composer global require hirak/prestissimo \
&& composer install --prefer-dist --no-interaction --no-dev -a \
&& composer global remove hirak/prestissimo \
# Delete cache directory to reduce size of image
&& rm -rf ~/.composer/cache
# Copy Code
# Excludes etc. are handled by the .dockerignore file
COPY . .
# Generate proxies for production usage
RUN set -ex \
&& composer dump-autoload --no-dev -a \
# RUN chmod +x ./build_environment.sh
# RUN chmod +x ./vendor/bin/doctrine
# RUN bash ./build_environment.sh -g local
&& ./vendor/bin/doctrine orm:generate-proxies \
# Re-generate autoload files with all the files copies
&& composer dump-autoload --no-dev -a
# Output log to stdout (only works after container has been started, this is why this is the last command)
# && ln -sf /proc/self/fd/1 logs/app.log
RUN chown -R www-data:www-data ./logs/
RUN chown -R www-data:www-data ./tmp/
# fastcgi/php-fpm server available on port 9000, needs extra nginx to be able to serve http
EXPOSE 9000
running docker build . works 100%
When I try bring up the container, the container exits with an error code of 70.
I think it has something to do with PHP FPM because of the error code but I cannot figure out what the issue is.
EDIT
Here's the docker-compose.yml
version: '3.1'
services:
api-backend:
build: ./
ports:
- 9000:9000
volumes:
- ./:/var/www/html:rw
user: 1000:1000
environment:
- "RDS_HOST=${RDS_HOST}"
- "RDS_PORT=${RDS_PORT}"
- "RDS_USER=${RDS_USER}"
- "RDS_DB=${RDS_DB}"
- "RDS_PW=${RDS_PW}"
- "USLN_CONFIG_FILE=${USLN_CONFIG_FILE}"
command: bash -c "vendor/bin/doctrine orm:generate-proxies && php-fpm"
links:
- 'postgres-backend'
depends_on:
- 'postgres-backend'
nginx-backend:
image: nginx:latest
ports:
- 8000:80
links:
- 'api-backend'
volumes:
- ./.nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- 'api-backend'
postgres-backend:
image: postgres:10.7
environment:
- "POSTGRES_PASSWORD=${RDS_PW}"
ports:
- 5432:5432
Related
I am using Nging+php-fpm in Docker on Mac OS.
I am trying to debug my app, but PHPStorm does not stop on breakpoints.
Here is my docker-compose.yml
version: '3'
services:
app_php:
build:
context: ./docker/php
dockerfile: Dockerfile
args:
USER_ID: 1000
GROUP_ID: 1000
restart: always
environment:
XDEBUG_CONFIG: remote_host=192.168.0.92
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./web:/var/www/html
depends_on:
- db
- redis
web_nginx:
image: nginx:1.17.9-alpine
restart: always
ports:
- 8090:80
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./web:/var/www/html
depends_on:
- app_php
Here is Dockerfile
FROM php:7.4-fpm-alpine3.11
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN apk add --no-cache \
shadow \
freetype \
freetype-dev \
ghostscript \
ghostscript-fonts \
gmp-dev \
graphicsmagick \
libjpeg-turbo \
libjpeg-turbo-dev \
libpng \
libpng-dev \
libwmf \
libxml2-dev \
libzip \
libzip-dev \
icu \
icu-dev \
git \
vim
# most likely used for local dev only
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN usermod -u ${USER_ID} www-data \
&& groupmod -g ${GROUP_ID} www-data
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-configure zip
RUN pecl install redis \
&& docker-php-ext-enable redis
RUN docker-php-ext-install -j$(nproc) gd mysqli soap zip intl
ENV PHP_CONFIG_DIR /usr/local/etc/php
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del -f .build-deps \
&& echo "zend_extension=$(find $(php-config --extension-dir) -name xdebug.so)" > $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_enable=1' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_port=10000' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_connect_back=1' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_autostart=0' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.idekey="PHPSTORM"' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.max_nesting_level=1000' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini
WORKDIR /var/www/html
And here are my configs in PHPStorm:
I tried to change XDEBUG_CONFIG: remote_host=192.168.0.92 to XDEBUG_CONFIG: remote_host=host.docker.internal but it does not help. Also I can reach 192.168.0.92:8090 by curl from inside docker container successfully.
Does anyone have an idea how to fix this issue?
Description:
One of my team member has migrate docker desktop to version 2.2.
Since, the php service won't start due to setfacl command from an entrypoint.sh.
Context:
We are working on a api-platform project in version 2.4.7.
Php Dockerfile:
# the different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
# https://docs.docker.com/compose/compose-file/#target
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION=7.3
ARG NGINX_VERSION=1.15
ARG VARNISH_VERSION=6.0
# "php" stage
FROM php:${PHP_VERSION}-fpm-alpine AS api_platform_php
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev openldap-dev && \
docker-php-ext-install ldap && \
docker-php-ext-enable ldap && \
apk del .build-deps
# persistent / runtime deps
RUN apk add --no-cache \
acl \
file \
gettext \
git \
;
ARG APCU_VERSION=5.1.17
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
libzip-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip --with-libzip; \
docker-php-ext-install -j$(nproc) \
intl \
pdo_mysql \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .api-phpexts-rundeps $runDeps; \
\
apk del .build-deps
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY docker/php/conf.d/api-platform.ini $PHP_INI_DIR/conf.d/api-platform.ini
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
# install Symfony Flex globally to speed up download of Composer packages (parallelized prefetching)
RUN set -eux; \
composer global require "symfony/flex" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \
composer clear-cache
ENV PATH="${PATH}:/root/.composer/vendor/bin"
WORKDIR /srv/api
# build for production
ARG APP_ENV=prod
ARG TRUSTED_HOSTS=localhost
ARG SENTRY_DSN=<SENTRY_DSN>
ARG BLACKFIRE_PROFILE_ON=false
# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json composer.lock symfony.lock ./
# do not use .env files in production
RUN echo '<?php return [];' > .env.local.php
RUN set -eux; \
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest; \
composer clear-cache
# copy only specifically what we need
COPY bin bin/
COPY config config/
COPY public public/
COPY src src/
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
VOLUME /srv/api/var
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
# Blackfire php probe
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini
ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]
# "nginx" stage
# depends on the "php" stage above
FROM nginx:${NGINX_VERSION}-alpine AS api_platform_nginx
COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
WORKDIR /srv/api
COPY --from=api_platform_php /srv/api/public public/
# "varnish" stage
# does not depend on any of the above stages, but placed here to keep everything in one Dockerfile
FROM cooptilleuls/varnish:${VARNISH_VERSION}-alpine AS api_platform_varnish
COPY docker/varnish/conf/default.vcl /usr/local/etc/varnish/default.vcl
docker-entrypoint:
#!/bin/sh
set -e
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$#"
fi
if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
PHP_INI_RECOMMENDED="$PHP_INI_DIR/php.ini-production"
if [ "$APP_ENV" != 'prod' ]; then
PHP_INI_RECOMMENDED="$PHP_INI_DIR/php.ini-development"
fi
ln -sf "$PHP_INI_RECOMMENDED" "$PHP_INI_DIR/php.ini"
mkdir -p var/cache var/log
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
if [ "$APP_ENV" != 'prod' ]; then
composer install --prefer-dist --no-progress --no-suggest --no-interaction
fi
echo "Waiting for db to be ready..."
until bin/console doctrine:query:sql "SELECT 1" > /dev/null 2>&1; do
sleep 1
done
# if [ "$APP_ENV" != 'prod' ]; then
# bin/console doctrine:schema:update --force --no-interaction
# fi
fi
crond -L /srv/api/logs/crond.log -b
exec docker-php-entrypoint "$#"
Commands in cause (in docker-entrypoint.sh):
mkdir -p var/cache var/log
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
Errors (durring php service up):
setfacl: var/log: Not supported
setfacl: var/log/dev.log: Not supported
Search line:
A new feature of docker-desktop is "New file sharing implementation" that replace (a kind of file sharing system) Samba by FUSE. It's made for developpers like us to improve performances when running symfony or react app through docker.
docker-desktop 2.2 release note here
a docker blog post about FUSE here
Do anyone has a same probleme and maybe a solution ?
I'm trying to install PHP Composer via Docker to be able to run composer as if it was installed on my host (MacOS) locally.
FROM php:7.2.13-apache
# install supporting packages
RUN apt-get update && apt-get install -y --fix-missing \
xz-utils \
build-essential \
pkg-config \
git-core \
autoconf \
libjpeg62-turbo-dev \
libsodium-dev \
libpng-dev \
libcurl4-openssl-dev \
libpq-dev \
libpspell-dev \
libsqlite3-dev \
libmagickwand-dev \
libzip-dev \
imagemagick \
subversion \
python \
g++ \
curl \
vim \
wget \
netcat \
chrpath
# install officially supported php extensions
RUN docker-php-ext-install \
iconv \
sodium \
opcache \
curl \
gd \
mysqli \
exif \
mbstring \
pdo \
pdo_pgsql \
pdo_mysql \
pdo_sqlite \
pspell \
pgsql \
soap \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
# PECL modules
RUN pecl install imagick \
&& pecl install xdebug-2.6.0
COPY ./xdebug/xdebug.ini /usr/local/etc/php/conf.d/
# Enable PECL modules
RUN docker-php-ext-enable imagick xdebug
# cleanup apt
RUN apt-get clean
RUN apt-get autoremove -y
# enable apache modules
RUN a2enmod rewrite headers cache cache_disk expires vhost_alias userdir autoindex
RUN service apache2 restart
RUN service apache-htcacheclean start
RUN usermod -u 1000 www-data
RUN usermod -G staff www-data
RUN chown -R www-data:www-data /var/www
RUN echo "memory_limit=-1" > "$PHP_INI_DIR/conf.d/memory-limit.ini" \
&& echo "date.timezone=${PHP_TIMEZONE:-UTC}" > "$PHP_INI_DIR/conf.d/date_timezone.ini"
RUN apk add --no-cache --virtual .build-deps zlib-dev libzip-dev \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --virtual .composer-phpext-rundeps $runDeps \
&& apk del .build-deps
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
ENV COMPOSER_VERSION 1.8.0
RUN curl --silent --fail --location --retry 3 --output /tmp/installer.php --url https://raw.githubusercontent.com/composer/getcomposer.org/b107d959a5924af895807021fcef4ffec5a76aa9/web/installer \
&& php -r " \
\$signature = '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061'; \
\$hash = hash('SHA384', file_get_contents('/tmp/installer.php')); \
if (!hash_equals(\$signature, \$hash)) { \
unlink('/tmp/installer.php'); \
echo 'Integrity check failed, installer is either corrupt or worse.' . PHP_EOL; \
exit(1); \
}" \
&& php /tmp/installer.php --no-ansi --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION} \
&& composer --ansi --version --no-interaction \
&& rm -rf /tmp/* /tmp/.htaccess
RUN chmod 700 /usr/bin/composer
COPY docker-entrypoint.sh /docker-entrypoint.sh
WORKDIR /var/www
CMD ["apache2-foreground"]
EXPOSE 80
docker-entrypoint.sh has the following code (from official composer docker page):
#!/usr/bin/env bash
isCommand() {
for cmd in \
"about" \
"archive" \
"browse" \
"check-platform-reqs" \
"clear-cache" \
"clearcache" \
"config" \
"create-project" \
"depends" \
"diagnose" \
"dump-autoload" \
"dumpautoload" \
"exec" \
"global" \
"help" \
"home" \
"info" \
"init" \
"install" \
"licenses" \
"list" \
"outdated" \
"prohibits" \
"remove" \
"require" \
"run-script" \
"search" \
"self-update" \
"selfupdate" \
"show" \
"status" \
"suggests" \
"update" \
"upgrade" \
"validate" \
"why" \
"why-not"
do
if [ -z "${cmd#"$1"}" ]; then
return 0
fi
done
return 1
}
# check if the first argument passed in looks like a flag
if [ "$(printf %c "$1")" = '-' ]; then
set -- /sbin/tini -- composer "$#"
# check if the first argument passed in is composer
elif [ "$1" = 'composer' ]; then
set -- /sbin/tini -- "$#"
# check if the first argument passed in matches a known command
elif isCommand "$1"; then
set -- /sbin/tini -- composer "$#"
fi
exec "$#"
docker-compose.yml has the following code:
version: '3'
services:
php:
container_name: local_php
build: .
image: php:7.2.13-apache
ports:
- "80:80"
- "443:443"
- "9001:9001"
volumes:
- ../:/var/www/html/
I expect to be able to run composer commands from the terminal (e.g. composer install) but I get the error -bash: composer: command not found each time I try to run any composer command after doing a Dockerfile build.
I finally figured it out; in case someone's trying to achieve the same you got two options basically:
Access php container bash (by using docker exec -it <container name> /bin/bash and navigate to the folder you wish to use composer on, and run composer commands. It might also be helpful to note that docker-compose run <container name> ls would show container's mounted volumes (if you wish to check / make sure).
Run the following commands in macos terminal, to be able to use composer as if it was installed locally:
#!/bin/bash
mkdir ~/.functions
echo '#!/bin/bash
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--workdir /var/www/html/${PWD##*/} \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/var/www/html/${PWD##*/} \
composer "$#"' > ~/.functions/composer
echo 'alias composer="sh ~/.functions/composer"' >> ~/.bash_profile
source ~/.bash_profile
Then in terminal try composer version to see if it's working; if not, try executing source ~/.bash_profile once more, and re-try.
Hope that helps!
I'm trying to setup development environment for one PHP application but I can't solve these two things:
sending emails (I would like use MailHog which is running but it seems that I haven't correct PHP configuration)
xdebug (is installed and log is working but I can not connect it from NetBeans IDE)
Here is my configuration:
docker-compose.yml:
version: "3.1"
services:
# MySQL
database:
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
MYSQL_DATABASE: testdb
image: mariadb
restart: always
volumes:
- "./docker/mariadb/data:/var/lib/mysql"
- "./docker/mariadb/init:/docker-entrypoint-initdb.d"
# PHP
php-fpm:
build:
context: ./docker/php-fpm
environment:
ENV_MODE: development
ENV_BRANCH: test
volumes:
- "./:/var/www/app"
# NGINX
webserver:
build:
context: ./docker/nginx
depends_on:
- php-fpm
environment:
MYSQL_DATABASE: testdb
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
MYSQL_ROOT_PASSWORD: root
links:
- database:mysql
- mailhog
ports:
- "80:80"
- "443:443"
volumes:
- "./:/var/www/inpage"
- "./docker/nginx/nginx.conf:/etc/nginx/nginx.conf"
- "./docker/nginx/inpage.inc.conf:/etc/nginx/inpage.inc.conf"
- "./docker/nginx/inpage-site.inc.conf:/etc/nginx/app-site.inc.conf"
- "./docker/nginx/sites/:/etc/nginx/sites-available"
- "./docker/nginx/conf.d/:/etc/nginx/conf.d"
# Adminer
adminer:
depends_on:
- database
environment:
ADMINER_DEFAULT_SERVER: database
image: adminer
ports:
- 8181:8080
restart: always
# MailHog
mailhog:
image: mailhog/mailhog
command: -smtp-bind-addr 127.0.0.1:1025
user: root
expose:
- 1025
- 8025
ports:
- 1025:1025
- 8025:8025
docker/php-fpm/Dockerfile:
# Customized Dockerfile from https://github.com/kporras07/docker-php.
FROM php:7.0-fpm-alpine
# Environment settings
ENV XDEBUG_VERSION 2.3.3
ENV PHP_MEMORY_LIMIT 256M
ENV PHP_MAX_EXECUTION_TIME 120
ENV PHP_POST_MAX_SIZE 100M
ENV PHP_UPLOAD_MAX_FILESIZE 100M
ENV PHP_INI_DIR /usr/local/etc/php
# Configure, build & install PHP
RUN docker-php-source extract \
&& apk --no-cache --update add \
libxml2-dev \
libpng \
libpng-dev \
libjpeg-turbo \
libjpeg-turbo-dev \
freetype-dev \
freetype \
libcurl \
curl-dev \
curl \
icu-dev \
g++ \
autoconf \
make \
libmcrypt-dev \
libmcrypt \
libintl \
openssl-dev \
re2c \
recode-dev \
sqlite-dev \
enchant-dev \
krb5-dev \
pcre-dev \
imagemagick-dev \
imagemagick \
libtool \
bzip2-dev \
freetds-dev \
freetype-dev \
gmp-dev \
imap-dev \
readline-dev \
recode-dev \
zip \
libzip \
libzip-dev \
libxslt \
libxslt-dev \
&& rm -rf /tmp/* \
&& rm -rf /var/cache/apk/* \
&& docker-php-ext-configure bcmath \
&& docker-php-ext-configure bz2 \
&& docker-php-ext-configure json \
&& docker-php-ext-configure session \
&& docker-php-ext-configure ctype \
&& docker-php-ext-configure curl \
&& docker-php-ext-configure tokenizer \
&& docker-php-ext-configure simplexml \
&& docker-php-ext-configure dom \
&& docker-php-ext-configure mbstring \
&& docker-php-ext-configure zip \
&& docker-php-ext-configure iconv \
&& docker-php-ext-configure xml \
&& docker-php-ext-configure opcache \
&& docker-php-ext-configure pdo \
&& docker-php-ext-configure pdo_mysql \
&& docker-php-ext-configure pdo_sqlite \
&& docker-php-ext-configure gettext \
&& docker-php-ext-configure gmp \
&& docker-php-ext-configure intl --enable-intl \
&& docker-php-ext-configure mcrypt \
&& docker-php-ext-configure phar \
&& docker-php-ext-configure soap \
&& docker-php-ext-configure sockets \
&& docker-php-ext-configure xml \
&& docker-php-ext-configure xsl \
&& docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
&& NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j${NPROC} gd \
&& docker-php-source delete
RUN docker-php-ext-install bcmath \
bz2 \
json \
session \
ctype \
curl \
tokenizer \
simplexml \
dom \
mbstring \
zip \
iconv \
xml \
opcache \
pdo \
pdo_mysql \
gettext \
gmp \
intl \
mcrypt \
phar \
soap \
sockets \
xml \
xsl
RUN apk update \
&& apk add ca-certificates wget \
&& update-ca-certificates
# Blackfire.io
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
# Xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
COPY ./xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
## mhsendmail for MailHog (https://github.com/mailhog/mhsendmail)
RUN apk update && apk add \
go \
git
RUN mkdir /root/go
ENV GOPATH=/root/go
ENV PATH=$PATH:$GOPATH/bin
RUN go get github.com/mailhog/mhsendmail
RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail
COPY ./php.ini /usr/local/etc/php/conf.d/docker-php.ini
# Fix iconv lib (https://github.com/docker-library/php/issues/240#issuecomment-305038173)
RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
# Cleanup
RUN rm -rf /tmp/* \
&& rm -rf /var/cache/apk/* \
&& rm -rf tmp/*
CMD ["php-fpm"]
EXPOSE 9000
docker/php-fpm/xdebug.ini:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so
xdebug.coverage_enable=0
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
;xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
;xdebug.remote_connect_back=1
xdebug.remote_log=/tmp/xdebug.log
;xdebug.remote_autostart=true
docker/php-fpm/php.ini:
memory_limit = ${PHP_MEMORY_LIMIT}
max_execution_time = ${PHP_MAX_EXECUTION_TIME}
post_max_size=${PHP_POST_MAX_SIZE}
upload_max_filesize=${PHP_UPLOAD_MAX_FILESIZE}
sendmail_path = /usr/bin/mhsendmail -S mailhog:1025 -t
I found a solution to the mailhog 'connection refused' part of this question on the mailhog github issues pages. You need to replace the sendmail_path statement in your
docker/php-fpm/php.ini with something like this (the -S option isn't supported, and the position of the quote marks is important):
sendmail_path = "/usr/bin/mhsendmail --smtp-addr=mailhog:1025"
Also I found that I didn't need to use the command, user or expose parts of the mailhog service section in the docker-compose file.
I have an symfony application, and i want to create docker container, that contains all needed files. The purpose is to spin up/down containers for scaling, without any other deploying processes. Just with given DB connection.
Building means, pretty much just git clone and running composer install, but some of symfony's post install scripts fail without configured DB.
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Can i not run these scripts when i'm building container? Or what the proper way to do symfony deployment?
Using Symfony 3.2, Doctrine2, PHP 7.1
The proper way to build a container without running the db script is by not running there scripts in the build,
Here is the one we use in production for api-platform:
FROM php:7.1-fpm-alpine
RUN apk add --no-cache --virtual .persistent-deps \
git \
icu-libs \
zlib \
postgresql-client
ENV APCU_VERSION 5.1.8
RUN set -xe \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
zlib-dev \
postgresql-dev \
sqlite-dev \
pcre-dev \
&& docker-php-ext-install \
intl \
mbstring \
pdo_mysql \
pdo_pgsql \
pdo \
pgsql \
zip \
pdo_sqlite \
&& pecl install \
apcu-${APCU_VERSION} \
&& docker-php-ext-enable --ini-name 20-apcu.ini apcu \
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache \
&& apk del .build-deps
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/install-composer.sh /usr/local/bin/docker-app-install-composer
RUN chmod +x /usr/local/bin/docker-app-install-composer
RUN set -xe \
&& apk add --no-cache --virtual .fetch-deps \
openssl \
&& docker-app-install-composer \
&& mv composer.phar /usr/local/bin/composer \
&& apk del .fetch-deps
ARG SYMFONY_ENV=dev
ENV SYMFONY_ENV=dev
RUN if [ "$SYMFONY_ENV" -ne "dev" ]; then \
sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_autostart=0' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_port=9001' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_log=/var/log/xdebug_remote.log' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
pecl install \
xdebug \
&& docker-php-ext-enable xdebug; \
fi;
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER 1
WORKDIR /srv/quotatis
COPY composer.json ./
COPY composer.lock ./
RUN mkdir -p \
var/cache \
var/logs \
var/sessions \
&& composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest -o -a \
&& composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest \
&& composer clear-cache \
# Permissions hack because setfacl does not work on Mac and Windows
&& chown -R www-data var
COPY app app/
COPY bin bin/
COPY src src/
COPY web web/
COPY etc etc/
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
COPY docker/php/start.sh /usr/local/bin/docker-app-start
RUN chmod +x /usr/local/bin/docker-app-start
CMD ["docker-app-start"]
You could see the whole stack (nginx + fpm + varnish on github)
The line that you need in here is this one
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest