From dd03aa611604556d3d66f65777316d525f6b2296 Mon Sep 17 00:00:00 2001 From: Jeff Lance Date: Fri, 24 Nov 2023 23:26:29 +0100 Subject: [PATCH] Initial commit --- README.md | 4 ++ app/index.php | 3 + docker/.env | 44 ++++++++++++ docker/docker-compose.yml | 141 ++++++++++++++++++++++++++++++++++++++ docker/php/Dockerfile | 21 ++++++ 5 files changed, 213 insertions(+) create mode 100644 README.md create mode 100644 app/index.php create mode 100644 docker/.env create mode 100644 docker/docker-compose.yml create mode 100644 docker/php/Dockerfile diff --git a/README.md b/README.md new file mode 100644 index 0000000..527bf11 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# DAMPPS: Docker Apache Mysql Postgresql Php Symfony + +This docker image runs an Apache server configured with PHP and a database server +upon choice between MariaDB, MySQL or PostgreSQL. diff --git a/app/index.php b/app/index.php new file mode 100644 index 0000000..5b63fb8 --- /dev/null +++ b/app/index.php @@ -0,0 +1,3 @@ + diff --git a/docker/.env b/docker/.env new file mode 100644 index 0000000..064366d --- /dev/null +++ b/docker/.env @@ -0,0 +1,44 @@ +# +# Docker +# +COMPOSE_PROJECT_NAME=project-1 +APP_NAME=my_app +APP_FOLDER="../app" + +# +# APACHE +# +HTTPD_SERVER_NAME=_ +HTTPD_LISTEN_PORT=80 + +# +# Adminer +# +ADMINER_PORT=81 + +# +# MariaDB +# +MARIADB_PORT=3306 +MARIADB_ROOT_PASSWORD=secret +MARIADB_USER=symfony +MARIADB_USER_PASSWORD=symfony +MARIADB_DATABASE=symfony + +# +# MariaDB +# +MYSQLDB_PORT=3306 +MYSQLDB_ROOT_PASSWORD=secret +MYSQLDB_USER=symfony +MYSQLDB_USER_PASSWORD=symfony +MYSQLDB_DATABASE=symfony + +# +# PostgreSQL +# +POSTGRES_PORT=5432 +POSTGRES_PASSWORD=secret +POSTGRES_USER=symfony +POSTGRES_DATABASE=symfony +POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..c46c1de --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,141 @@ +--- +version: '3.8' + +networks: + mynetwork: + name: "${APP_NAME}-net" + +services: + # apache: + # container_name: "${APP_NAME}-apache" + # labels: + # local.project: "${APP_NAME}" + # build: + # context: . + # dockerfile: apache/Dockerfile + # restart: always + # ports: + # - "${HTTPD_LISTEN_PORT}:80" + # volumes: + # - "${APP_FOLDER}:/usr/local/apache2/htdocs" + # - ./apache/vhosts:/etc/apache2/sites-enabled + # - ./tmp:/tmp + # - ./apache/logs:/var/log/httpd:cached + # depends_on: + # - php + # networks: + # - mynetwork + + php: + container_name: "${APP_NAME}-php" + labels: + local.project: "${APP_NAME}" + build: + context: . + dockerfile: php/Dockerfile + restart: always + ports: + - "${HTTPD_LISTEN_PORT}:80" + volumes: + - "${APP_FOLDER}:/var/www/html" + - ./apache/vhosts:/etc/apache2/sites-enabled + - ./apache/logs:/var/log/apache2:cached + - ./tmp:/tmp + networks: + - mynetwork + + mariadb: + container_name: "${APP_NAME}-mariadb" + labels: + local.project: "${APP_NAME}" + image: mariadb + restart: always + ports: + - "${MARIADB_PORT}:3306" + volumes: + - db_data:/var/lib/mysql + - ./mariadb:/etc/mysql + environment: + MARIADB_ROOT_PASSWORD: "${MARIADB_ROOT_PASSWORD}" + MARIADB_USER: "${MARIADB_USER}" + MARIADB_PASSWORD: "${MARIADB_USER_PASSWORD}" + MARIADB_DATABASE: "${MARIADB_DATABASE}" + healthcheck: + test: mysqladmin ping -h 127.0.0.1 -u root --password=$${MARIADB_ROOT_PASSWORD} + interval: 5s + retries: 5 + networks: + - mynetwork + profiles: + - mariadb + + mysql: + container_name: "${APP_NAME}-mysql" + labels: + local.project: "${APP_NAME}" + image: mysql + restart: always + ports: + - "${MYSQLDB_PORT}:3306" + volumes: + - db_data:/var/lib/mysql + - ./mysql:/etc/mysql + environment: + MYSQL_ROOT_PASSWORD: "${MYSQLDB_ROOT_PASSWORD}" + MYSQL_USER: "${MYSQLDB_USER}" + MYSQL_PASSWORD: "${MYSQLDB_USER_PASSWORD}" + MYSQL_DATABASE: "${MYSQLDB_DATABASE}" + healthcheck: + test: mysqladmin ping -h 127.0.0.1 -u root --password=$${MYSQLDB_ROOT_PASSWORD} + interval: 5s + retries: 5 + networks: + - mynetwork + profiles: + - mysql + + pgsql: + container_name: "${APP_NAME}-pgsql" + labels: + local.project: "${APP_NAME}" + image: postgres + restart: always + ports: + - "${POSTGRES_PORT}:5432" + volumes: + - db_data:/var/lib/postgresql/data + - ./postgresql:/etc/postgresql + environment: + POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" + POSTGRES_USER: "${POSTGRES_USER}" + POSTGRES_DB: "${POSTGRES_DATABASE}" + POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256 + healthcheck: + test: pg_isready -h 127.0.0.1 -u $${POSTGRES_USER} + interval: 5s + retries: 5 + networks: + - mynetwork + profiles: + - pgsql + + adminer: + container_name: "${APP_NAME}-adminer" + labels: + local.project: "${APP_NAME}" + image: adminer + restart: always + environment: + ADMINER_DESIGN: 'dracula' + ADMINER_PLUGINS: 'tables-filter tinymce' + ports: + - "${ADMINER_PORT}:8080" + depends_on: + # - apache + - php + networks: + - mynetwork + profiles: ['mariadb', 'mysql', 'pgsql'] + +volumes: + db_data: diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 0000000..221c94c --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1 +FROM php:8.1-apache + +# make some stuff +RUN apt-get update +RUN apt-get install -y --no-install-recommends nano + +# we get a tool used to easily install a PHP extension +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +# and run it +RUN chmod +x /usr/local/bin/install-php-extensions && \ + install-php-extensions amqp gd exif intl mbstring opcache pdo_mysql pdo_pgsql redis xdebug xsl zip && \ + install-php-extensions @composer + +# add symfony-cli repo +RUN curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | bash + +# and install it +RUN apt-get install -y --no-install-recommends symfony-cli +