Upgrade Dockerfile
This commit is contained in:
parent
1f61df9cf0
commit
59b584a576
@ -12,7 +12,6 @@
|
||||
**/Thumbs.db
|
||||
.editorconfig
|
||||
.env*
|
||||
!.env.local.php
|
||||
.php_cs.cache
|
||||
bin/*
|
||||
!bin/console
|
||||
|
73
Dockerfile
73
Dockerfile
@ -4,60 +4,66 @@
|
||||
|
||||
|
||||
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
|
||||
ARG PHP_VERSION=7.3
|
||||
ARG NGINX_VERSION=1.15
|
||||
|
||||
ARG PHP_VERSION=7.4
|
||||
ARG NGINX_VERSION=1.17
|
||||
|
||||
# "php" stage
|
||||
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_docker_php
|
||||
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php
|
||||
|
||||
# persistent / runtime deps
|
||||
RUN apk add --no-cache \
|
||||
acl \
|
||||
file \
|
||||
gettext \
|
||||
git \
|
||||
jq \
|
||||
;
|
||||
acl \
|
||||
fcgi \
|
||||
file \
|
||||
gettext \
|
||||
git \
|
||||
jq \
|
||||
;
|
||||
|
||||
ARG APCU_VERSION=5.1.17
|
||||
ARG APCU_VERSION=5.1.18
|
||||
RUN set -eux; \
|
||||
apk add --no-cache --virtual .build-deps \
|
||||
$PHPIZE_DEPS \
|
||||
icu-dev \
|
||||
libzip-dev \
|
||||
postgresql-dev \
|
||||
zlib-dev \
|
||||
$PHPIZE_DEPS \
|
||||
icu-dev \
|
||||
libzip-dev \
|
||||
zlib-dev \
|
||||
; \
|
||||
\
|
||||
docker-php-ext-configure zip --with-libzip; \
|
||||
docker-php-ext-install -j$(nproc) \
|
||||
intl \
|
||||
zip \
|
||||
intl \
|
||||
zip \
|
||||
; \
|
||||
pecl install \
|
||||
apcu-${APCU_VERSION} \
|
||||
apcu-${APCU_VERSION} \
|
||||
; \
|
||||
pecl clear-cache; \
|
||||
docker-php-ext-enable \
|
||||
apcu \
|
||||
opcache \
|
||||
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 }' \
|
||||
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 .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/symfony.ini $PHP_INI_DIR/conf.d/symfony.ini
|
||||
|
||||
RUN set -eux; \
|
||||
{ \
|
||||
echo '[www]'; \
|
||||
echo 'ping.path = /ping'; \
|
||||
} | tee /usr/local/etc/php-fpm.d/docker-healthcheck.conf
|
||||
|
||||
# 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)
|
||||
@ -79,7 +85,7 @@ ENV STABILITY ${STABILITY:-stable}
|
||||
ARG SYMFONY_VERSION=""
|
||||
|
||||
# Download the Symfony skeleton and leverage Docker cache layers
|
||||
RUN composer create-project "symfony/skeleton ${SYMFONY_VERSION}" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-scripts --no-plugins --no-interaction; \
|
||||
RUN composer create-project "symfony/skeleton ${SYMFONY_VERSION}" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-scripts --no-interaction; \
|
||||
composer clear-cache
|
||||
|
||||
###> recipes ###
|
||||
@ -93,6 +99,11 @@ RUN set -eux; \
|
||||
composer run-script --no-dev post-install-cmd; sync
|
||||
VOLUME /srv/app/var
|
||||
|
||||
COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
|
||||
RUN chmod +x /usr/local/bin/docker-healthcheck
|
||||
|
||||
HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]
|
||||
|
||||
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint
|
||||
|
||||
@ -102,16 +113,16 @@ CMD ["php-fpm"]
|
||||
|
||||
# "nginx" stage
|
||||
# depends on the "php" stage above
|
||||
FROM nginx:${NGINX_VERSION}-alpine AS symfony_docker_nginx
|
||||
FROM nginx:${NGINX_VERSION}-alpine AS symfony_nginx
|
||||
|
||||
COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
WORKDIR /srv/app
|
||||
|
||||
COPY --from=symfony_docker_php /srv/app/public public/
|
||||
COPY --from=symfony_php /srv/app/public public/
|
||||
|
||||
# "h2-proxy-cert" stage
|
||||
FROM alpine:latest AS symfony_docker_h2-proxy-cert
|
||||
FROM alpine:latest AS symfony_h2-proxy-cert
|
||||
|
||||
RUN apk add --no-cache openssl
|
||||
|
||||
@ -124,8 +135,8 @@ RUN openssl req -new -passout pass:NotSecure -key server.key -out server.csr \
|
||||
RUN openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt
|
||||
|
||||
### "h2-proxy" stage
|
||||
FROM nginx:${NGINX_VERSION}-alpine AS symfony_docker_h2-proxy
|
||||
FROM nginx:${NGINX_VERSION}-alpine AS symfony_h2-proxy
|
||||
|
||||
RUN mkdir -p /etc/nginx/ssl/
|
||||
COPY --from=symfony_docker_h2-proxy-cert server.key server.crt /etc/nginx/ssl/
|
||||
COPY --from=symfony_h2-proxy-cert server.key server.crt /etc/nginx/ssl/
|
||||
COPY ./docker/h2-proxy/default.conf /etc/nginx/conf.d/default.conf
|
||||
|
19
README.md
19
README.md
@ -37,9 +37,9 @@ it's recommended to add a custom stage to the end of the `Dockerfile`.
|
||||
|
||||
```Dockerfile
|
||||
# Dockerfile
|
||||
FROM symfony_docker_php as symfony_docker_php_dev
|
||||
FROM symfony_php as symfony_php_dev
|
||||
|
||||
ARG XDEBUG_VERSION=2.6.0
|
||||
ARG XDEBUG_VERSION=2.8.0
|
||||
RUN set -eux; \
|
||||
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
|
||||
pecl install xdebug-$XDEBUG_VERSION; \
|
||||
@ -58,10 +58,10 @@ As example, an override could look like this:
|
||||
version: "3.4"
|
||||
|
||||
services:
|
||||
app:
|
||||
php:
|
||||
build:
|
||||
context: .
|
||||
target: symfony_docker_php_dev
|
||||
target: symfony_php_dev
|
||||
environment:
|
||||
# See https://docs.docker.com/docker-for-mac/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
|
||||
# See https://github.com/docker/for-linux/issues/264
|
||||
@ -73,7 +73,7 @@ services:
|
||||
idekey=PHPSTORM
|
||||
# This should correspond to the server declared in PHPStorm `Preferences | Languages & Frameworks | PHP | Servers`
|
||||
# Then PHPStorm will use the corresponding path mappings
|
||||
PHP_IDE_CONFIG: serverName=symfony-docker
|
||||
PHP_IDE_CONFIG: serverName=symfony
|
||||
```
|
||||
|
||||
Then run:
|
||||
@ -82,7 +82,7 @@ Then run:
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
If `docker-compose.yaml` and a `docker-compose.override.yaml` are present on the same directory level, Docker Compose combines the two files into a single configuration, applying the configuration in the `docker-compose.override.yaml` file over and in addition to the values in the `docker-compose.yaml` file.
|
||||
If `docker-compose.yml` and a `docker-compose.override.yml` are present on the same directory level, Docker Compose combines the two files into a single configuration, applying the configuration in the `docker-compose.override.yml` file over and in addition to the values in the `docker-compose.yml` file.
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
@ -91,11 +91,8 @@ Inspect the installation with the following command. The requested Xdebug versio
|
||||
```bash
|
||||
$ docker-compose exec php php --version
|
||||
|
||||
PHP 7.2.8 (cli) (built: Jul 21 2018 08:09:37) ( NTS )
|
||||
Copyright (c) 1997-2018 The PHP Group
|
||||
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
|
||||
with Zend OPcache v7.2.8, Copyright (c) 1999-2018, by Zend Technologies
|
||||
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
|
||||
PHP ...
|
||||
with Xdebug v2.8.0 ...
|
||||
```
|
||||
|
||||
### Editing Permissions on Linux
|
||||
|
@ -4,10 +4,15 @@ services:
|
||||
php:
|
||||
build:
|
||||
context: .
|
||||
target: symfony_docker_php
|
||||
target: symfony_php
|
||||
args:
|
||||
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
|
||||
STABILITY: ${STABILITY:-stable}
|
||||
healthcheck:
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 3
|
||||
start_period: 30s
|
||||
volumes:
|
||||
# Comment out the next line in production
|
||||
- ./:/srv/app:rw,cached
|
||||
@ -22,7 +27,7 @@ services:
|
||||
nginx:
|
||||
build:
|
||||
context: .
|
||||
target: symfony_docker_nginx
|
||||
target: symfony_nginx
|
||||
depends_on:
|
||||
- php
|
||||
volumes:
|
||||
@ -36,7 +41,7 @@ services:
|
||||
h2-proxy:
|
||||
build:
|
||||
context: .
|
||||
target: symfony_docker_h2-proxy
|
||||
target: symfony_h2-proxy
|
||||
depends_on:
|
||||
- nginx
|
||||
volumes:
|
@ -13,6 +13,8 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
||||
fi
|
||||
ln -sf "$PHP_INI_RECOMMENDED" "$PHP_INI_DIR/php.ini"
|
||||
|
||||
mkdir -p var/cache var/log
|
||||
|
||||
# The first time volumes are mounted, the project needs to be recreated
|
||||
if [ ! -f composer.json ]; then
|
||||
composer create-project "symfony/skeleton $SYMFONY_VERSION" tmp --stability=$STABILITY --prefer-dist --no-progress --no-interaction
|
||||
@ -26,7 +28,6 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
||||
composer install --prefer-dist --no-progress --no-suggest --no-interaction
|
||||
fi
|
||||
|
||||
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
|
||||
fi
|
||||
|
12
docker/php/docker-healthcheck.sh
Normal file
12
docker/php/docker-healthcheck.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
export SCRIPT_NAME=/ping
|
||||
export SCRIPT_FILENAME=/ping
|
||||
export REQUEST_METHOD=GET
|
||||
|
||||
if cgi-fcgi -bind -connect 127.0.0.1:9000; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 1
|
Loading…
x
Reference in New Issue
Block a user