Created
January 14, 2023 11:33
-
-
Save Astro-Otter-Space/44e32650c9d6a3a6422753a4e87181f9 to your computer and use it in GitHub Desktop.
Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.4" | |
services: | |
# PHP | |
php: | |
build: | |
context: . | |
target: app_php | |
restart: unless-stopped | |
volumes: | |
- ./:/var/www/deep-space-objects | |
- php_socket:/var/run/php | |
healthcheck: | |
interval: 10s | |
timeout: 3s | |
retries: 3 | |
start_period: 30s | |
env_file: | |
- ".env" | |
environment: | |
- SSH_AUTH_SOCK=/ssh-agent | |
- TERM=xterm-color | |
container_name: dso_php | |
extra_hosts: | |
- host.docker.internal:host-gateway | |
# Node JS / assets | |
# node: | |
# build: | |
# context: . | |
# target: app_node | |
# volumes: | |
# - ./:/var/www/deep-space-objects | |
# ports: | |
# - target: 8000 | |
# NGINX | |
nginx: | |
build: | |
context: . | |
target: app_nginx | |
args: | |
NGINX_HOST: ${NGINX_HOST} | |
UID: ${SITE_UID} | |
container_name: dso_nginx | |
ports: | |
- "80:80" | |
- "443:443" | |
depends_on: | |
- php | |
volumes: | |
- .:/var/www/deep-space-objects | |
- ./logs/nginx/:/var/log/nginx:cached | |
#- /etc/letsencrypt/:/etc/letsencrypt/ | |
env_file: | |
- .env | |
environment: | |
- NGINX_HOST=${NGINX_HOST} | |
# ElasticSearch | |
elasticsearch: | |
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.7 | |
container_name: dso_elasticsearch | |
hostname: elasticsearch | |
volumes: | |
- es_data:/usr/share/elasticsearch/data | |
- es_plugins:/usr/share/elasticsearch/plugins | |
environment: | |
- xpack.security.enabled=false | |
- discovery.type=single-node | |
- cluster.name=demo | |
- bootstrap.memory_lock=true | |
- http.cors.enabled=true | |
- http.cors.allow-origin=* | |
- http.cors.allow-headers=X-Requested-With,Content-Type,Content-Length,Authorization | |
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" | |
ulimits: | |
memlock: | |
soft: -1 | |
hard: -1 | |
nofile: | |
soft: 65536 | |
hard: 65536 | |
cap_add: | |
- IPC_LOCK | |
ports: | |
- "9200:9200" | |
# Kibana | |
kibana: | |
image: docker.elastic.co/kibana/kibana:7.17.7 | |
container_name: dso_kibana | |
environment: | |
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200 | |
links: | |
- elasticsearch | |
ports: | |
- "5601:5601" | |
# MySQL | |
database: | |
image: mariadb:10.3 | |
container_name: dso_db | |
hostname: database | |
cap_add: | |
- SYS_NICE | |
restart: always | |
volumes: | |
- db_data:/var/lib/mysql/ | |
#- ./docker/db/init.sql:/docker-entrypoint-initdb.d/init.sql | |
env_file: | |
- ".env" | |
environment: | |
- MYSQL_DATABASE=${DATABASE_NAME} | |
- MYSQL_USER=${DATABASE_USER} | |
- MYSQL_PASSWORD=${DATABASE_PASSWORD} | |
- MYSQL_ROOT_PASSWORD=${DATABASE_ROOT_PASSWORD} | |
ports: | |
- '3306:3306' | |
#MAIL - SMTP Server | |
# mail: | |
# image: bytemark/smtp | |
# container_name: dso_mail | |
# restart: always | |
# networks: | |
# - dso_stack | |
# redis | |
redis: | |
image: redis:6.0-alpine | |
hostname: redis | |
container_name: dso_redis | |
restart: always | |
ports: | |
- '6379:6379' | |
volumes: | |
php_socket: | |
db_data: { } | |
es_data: { } | |
es_plugins: { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#syntax=docker/dockerfile:1.4 | |
ARG PHP_VERSION=8.1 | |
ARG NODE_VERSION=14 | |
####################### | |
# Node | |
####################### | |
FROM node:${NODE_VERSION}-alpine AS app_node | |
WORKDIR /var/www/deep-space-objects | |
#RUN mkdir public | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
RUN npm run build | |
# 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 | |
####################### | |
# PHP | |
####################### | |
FROM php:${PHP_VERSION}-fpm-alpine AS app_php | |
ENV APP_ENV=dev | |
WORKDIR /var/www/deep-space-objects | |
COPY --from=mlocati/php-extension-installer --link /usr/bin/install-php-extensions /usr/local/bin/ | |
# persistent / runtime deps | |
RUN apk add --no-cache \ | |
acl \ | |
fcgi \ | |
file \ | |
gettext \ | |
git \ | |
libsodium-dev \ | |
curl \ | |
openssl \ | |
apt-transport-https \ | |
; | |
RUN set -eux; \ | |
install-php-extensions \ | |
intl \ | |
zip \ | |
apcu \ | |
opcache \ | |
pdo \ | |
pdo_mysql \ | |
gd \ | |
sodium \ | |
; | |
###> recipes ### | |
###< recipes ### | |
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" | |
COPY --link docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/ | |
COPY --link docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/ | |
COPY --link docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf | |
RUN mkdir -p /var/run/php | |
COPY --link 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 --link docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck | |
RUN chmod +x /usr/local/bin/docker-entrypoint | |
ENTRYPOINT ["docker-entrypoint"] | |
CMD ["php-fpm"] | |
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser | |
ENV COMPOSER_ALLOW_SUPERUSER=1 | |
ENV PATH="${PATH}:/root/.composer/vendor/bin" | |
COPY --from=composer:2 --link /usr/bin/composer /usr/bin/composer | |
# prevent the reinstallation of vendors at every changes in the source code | |
COPY composer.* symfony.* ./ | |
RUN set -eux; \ | |
if [ -f composer.json ]; then \ | |
composer config --json extra.symfony.docker 'true'; \ | |
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \ | |
composer clear-cache; \ | |
fi | |
# copy sources | |
COPY --link . . | |
#RUN rm -Rf docker/ | |
RUN set -eux; \ | |
mkdir -p var/cache var/log; \ | |
if [ -f composer.json ]; then \ | |
composer dump-autoload --classmap-authoritative --no-dev; \ | |
composer dump-env prod; \ | |
composer run-script --no-dev post-install-cmd; \ | |
chmod +x bin/console; sync; \ | |
fi | |
COPY --from=app_php --link /var/www/deep-space-objects/public public/ | |
####################### | |
# Nginx | |
####################### | |
FROM debian:stretch as app_nginx | |
ARG NGINX_HOST | |
ARG UID | |
# Install nginx | |
RUN apt-get update && apt-get install -y nginx wget | |
# Instal certbot for SSL | |
#RUN apt-get install certbot python-certbot-nginx -t stretch-backports | |
# Configure Nginx | |
ADD nginx.conf /etc/nginx/ | |
ADD symfony.conf /etc/nginx/sites-available/ | |
#RUN envsubst "${NGINX_HOST}" < /etc/nginx/sites-available/default.template > /etc/nginx/sites-available/symfony.conf && nginx -g 'daemon off;' | |
RUN sed "/server_name nginx_host;/c\ server_name ${NGINX_HOST};" -i /etc/nginx/sites-available/symfony.conf | |
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf | |
# Configure the virtual host | |
RUN ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/symfony | |
RUN rm /etc/nginx/sites-enabled/default | |
# Add certificate SSL | |
#RUN certbot --nginx certonly | |
RUN usermod -u ${UID} www-data | |
# Run Nginx | |
CMD ["nginx"] | |
# Expose ports | |
EXPOSE 80 | |
EXPOSE 443 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment