Upgrade Dockerfile
This commit is contained in:
parent
1f61df9cf0
commit
59b584a576
@ -12,7 +12,6 @@
|
|||||||
**/Thumbs.db
|
**/Thumbs.db
|
||||||
.editorconfig
|
.editorconfig
|
||||||
.env*
|
.env*
|
||||||
!.env.local.php
|
|
||||||
.php_cs.cache
|
.php_cs.cache
|
||||||
bin/*
|
bin/*
|
||||||
!bin/console
|
!bin/console
|
||||||
|
73
Dockerfile
73
Dockerfile
@ -4,60 +4,66 @@
|
|||||||
|
|
||||||
|
|
||||||
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
|
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
|
||||||
ARG PHP_VERSION=7.3
|
ARG PHP_VERSION=7.4
|
||||||
ARG NGINX_VERSION=1.15
|
ARG NGINX_VERSION=1.17
|
||||||
|
|
||||||
|
|
||||||
# "php" stage
|
# "php" stage
|
||||||
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_docker_php
|
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php
|
||||||
|
|
||||||
# persistent / runtime deps
|
# persistent / runtime deps
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
acl \
|
acl \
|
||||||
file \
|
fcgi \
|
||||||
gettext \
|
file \
|
||||||
git \
|
gettext \
|
||||||
jq \
|
git \
|
||||||
;
|
jq \
|
||||||
|
;
|
||||||
|
|
||||||
ARG APCU_VERSION=5.1.17
|
ARG APCU_VERSION=5.1.18
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apk add --no-cache --virtual .build-deps \
|
apk add --no-cache --virtual .build-deps \
|
||||||
$PHPIZE_DEPS \
|
$PHPIZE_DEPS \
|
||||||
icu-dev \
|
icu-dev \
|
||||||
libzip-dev \
|
libzip-dev \
|
||||||
postgresql-dev \
|
zlib-dev \
|
||||||
zlib-dev \
|
|
||||||
; \
|
; \
|
||||||
\
|
\
|
||||||
docker-php-ext-configure zip --with-libzip; \
|
docker-php-ext-configure zip --with-libzip; \
|
||||||
docker-php-ext-install -j$(nproc) \
|
docker-php-ext-install -j$(nproc) \
|
||||||
intl \
|
intl \
|
||||||
zip \
|
zip \
|
||||||
; \
|
; \
|
||||||
pecl install \
|
pecl install \
|
||||||
apcu-${APCU_VERSION} \
|
apcu-${APCU_VERSION} \
|
||||||
; \
|
; \
|
||||||
pecl clear-cache; \
|
pecl clear-cache; \
|
||||||
docker-php-ext-enable \
|
docker-php-ext-enable \
|
||||||
apcu \
|
apcu \
|
||||||
opcache \
|
opcache \
|
||||||
; \
|
; \
|
||||||
\
|
\
|
||||||
runDeps="$( \
|
runDeps="$( \
|
||||||
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
|
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
|
||||||
| tr ',' '\n' \
|
| tr ',' '\n' \
|
||||||
| sort -u \
|
| sort -u \
|
||||||
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
|
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
|
||||||
)"; \
|
)"; \
|
||||||
apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
|
apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
|
||||||
\
|
\
|
||||||
apk del .build-deps
|
apk del .build-deps
|
||||||
|
|
||||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
|
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
|
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
|
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
|
||||||
ENV COMPOSER_ALLOW_SUPERUSER=1
|
ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||||
# install Symfony Flex globally to speed up download of Composer packages (parallelized prefetching)
|
# install Symfony Flex globally to speed up download of Composer packages (parallelized prefetching)
|
||||||
@ -79,7 +85,7 @@ ENV STABILITY ${STABILITY:-stable}
|
|||||||
ARG SYMFONY_VERSION=""
|
ARG SYMFONY_VERSION=""
|
||||||
|
|
||||||
# Download the Symfony skeleton and leverage Docker cache layers
|
# 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
|
composer clear-cache
|
||||||
|
|
||||||
###> recipes ###
|
###> recipes ###
|
||||||
@ -93,6 +99,11 @@ RUN set -eux; \
|
|||||||
composer run-script --no-dev post-install-cmd; sync
|
composer run-script --no-dev post-install-cmd; sync
|
||||||
VOLUME /srv/app/var
|
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
|
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||||
RUN chmod +x /usr/local/bin/docker-entrypoint
|
RUN chmod +x /usr/local/bin/docker-entrypoint
|
||||||
|
|
||||||
@ -102,16 +113,16 @@ CMD ["php-fpm"]
|
|||||||
|
|
||||||
# "nginx" stage
|
# "nginx" stage
|
||||||
# depends on the "php" stage above
|
# 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
|
COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
WORKDIR /srv/app
|
WORKDIR /srv/app
|
||||||
|
|
||||||
COPY --from=symfony_docker_php /srv/app/public public/
|
COPY --from=symfony_php /srv/app/public public/
|
||||||
|
|
||||||
# "h2-proxy-cert" stage
|
# "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
|
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
|
RUN openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt
|
||||||
|
|
||||||
### "h2-proxy" stage
|
### "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/
|
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
|
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
|
||||||
# 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; \
|
RUN set -eux; \
|
||||||
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
|
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
|
||||||
pecl install xdebug-$XDEBUG_VERSION; \
|
pecl install xdebug-$XDEBUG_VERSION; \
|
||||||
@ -58,10 +58,10 @@ As example, an override could look like this:
|
|||||||
version: "3.4"
|
version: "3.4"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
php:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: symfony_docker_php_dev
|
target: symfony_php_dev
|
||||||
environment:
|
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://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
|
# See https://github.com/docker/for-linux/issues/264
|
||||||
@ -73,7 +73,7 @@ services:
|
|||||||
idekey=PHPSTORM
|
idekey=PHPSTORM
|
||||||
# This should correspond to the server declared in PHPStorm `Preferences | Languages & Frameworks | PHP | Servers`
|
# This should correspond to the server declared in PHPStorm `Preferences | Languages & Frameworks | PHP | Servers`
|
||||||
# Then PHPStorm will use the corresponding path mappings
|
# Then PHPStorm will use the corresponding path mappings
|
||||||
PHP_IDE_CONFIG: serverName=symfony-docker
|
PHP_IDE_CONFIG: serverName=symfony
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run:
|
Then run:
|
||||||
@ -82,7 +82,7 @@ Then run:
|
|||||||
docker-compose up -d
|
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
|
### Troubleshooting
|
||||||
|
|
||||||
@ -91,11 +91,8 @@ Inspect the installation with the following command. The requested Xdebug versio
|
|||||||
```bash
|
```bash
|
||||||
$ docker-compose exec php php --version
|
$ docker-compose exec php php --version
|
||||||
|
|
||||||
PHP 7.2.8 (cli) (built: Jul 21 2018 08:09:37) ( NTS )
|
PHP ...
|
||||||
Copyright (c) 1997-2018 The PHP Group
|
with Xdebug v2.8.0 ...
|
||||||
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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Editing Permissions on Linux
|
### Editing Permissions on Linux
|
||||||
|
@ -4,10 +4,15 @@ services:
|
|||||||
php:
|
php:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: symfony_docker_php
|
target: symfony_php
|
||||||
args:
|
args:
|
||||||
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
|
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
|
||||||
STABILITY: ${STABILITY:-stable}
|
STABILITY: ${STABILITY:-stable}
|
||||||
|
healthcheck:
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 3
|
||||||
|
start_period: 30s
|
||||||
volumes:
|
volumes:
|
||||||
# Comment out the next line in production
|
# Comment out the next line in production
|
||||||
- ./:/srv/app:rw,cached
|
- ./:/srv/app:rw,cached
|
||||||
@ -22,7 +27,7 @@ services:
|
|||||||
nginx:
|
nginx:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: symfony_docker_nginx
|
target: symfony_nginx
|
||||||
depends_on:
|
depends_on:
|
||||||
- php
|
- php
|
||||||
volumes:
|
volumes:
|
||||||
@ -36,7 +41,7 @@ services:
|
|||||||
h2-proxy:
|
h2-proxy:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: symfony_docker_h2-proxy
|
target: symfony_h2-proxy
|
||||||
depends_on:
|
depends_on:
|
||||||
- nginx
|
- nginx
|
||||||
volumes:
|
volumes:
|
@ -13,6 +13,8 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
|||||||
fi
|
fi
|
||||||
ln -sf "$PHP_INI_RECOMMENDED" "$PHP_INI_DIR/php.ini"
|
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
|
# The first time volumes are mounted, the project needs to be recreated
|
||||||
if [ ! -f composer.json ]; then
|
if [ ! -f composer.json ]; then
|
||||||
composer create-project "symfony/skeleton $SYMFONY_VERSION" tmp --stability=$STABILITY --prefer-dist --no-progress --no-interaction
|
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
|
composer install --prefer-dist --no-progress --no-suggest --no-interaction
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p var/cache var/log
|
|
||||||
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
||||||
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
||||||
fi
|
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