WIP: added phpmyadmin, init with database dump

This commit is contained in:
marko
2024-07-15 19:43:24 +02:00
parent 15111e3e1a
commit 81b943dcd5
8 changed files with 98 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
# don't commit credentials
db_root_password.txt
db_password.txt
# sql dump shall be created new every time (from the productive system)
cwsvjudo.sql

View File

@@ -0,0 +1,11 @@
# select base image
FROM php:fpm
# startup scripts for the image
# - docker-php-ext-install -- install helper script from PHP
RUN docker-php-ext-install pdo pdo_mysql
# install and add xdebug extension
# @todo What is pecl?
# @todo What is xdebug and how do I use it?
RUN pecl install xdebug && docker-php-ext-enable xdebug

View File

@@ -0,0 +1,14 @@
<?php
# demo file testing the docker installed db
$pdo = new PDO(
'mysql:dbname=tutorial; host=mysql',
'tutorial',
'secret',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$query = $pdo->query('SHOW VARIABLES like "version"');
$row = $query->fetch();
echo 'MYSQL version: '. $row['Value'];

View File

@@ -0,0 +1 @@
insert_MYSQL_PASSWORD_here_and_remove_template_in_filename

View File

@@ -0,0 +1 @@
insert_MYSQL_ROOT_PASSWORD_here_and_remove_template_in_filename

View File

@@ -0,0 +1,8 @@
#! /usr/bin/env bash
# stop all containers
docker-compose down --remove-orphans
# delete all containers
docker rm -f $(docker ps -a -q)
# delete all volumes
docker volume rm $(docker volume ls -q)

View File

@@ -1,8 +1,9 @@
# version for the docker compose file to use
version: "3"
# a dict of services running in the container label: {<service>} label is a self defined name for the service
services:
# the web service
# the webserver service
web:
image: nginx:latest
# port forwarding
@@ -13,7 +14,60 @@ services:
volumes:
- ./nginx.conf:/etc/nginx/conf.d/nginx.conf
- ./app:/app
# php and extensions
php:
image: php:fpm
# use pre-build image from docker..
# image: php:fpm
# .. or build your own image
build:
context: .
dockerfile: PHP.dockerfile
# files and directories to be available in the container
# @todo Except from better structuring: Is there a reason for not having the volumes as one central list?
volumes:
- ./app:/app
# install a dm
# @todo Maybe use postgre instead?
database:
image: mariadb:latest
restart: always
# define environment variables
# @todo Should credentials be placed here? Even if it is just a test environment
environment:
MYSQL_USER: 'cwsvjudo'
MYSQL_DATABASE: 'cwsvjudo'
MYSQL_TCP_PORT: '3306'
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_PASSWORD_FILE: /run/secrets/db_password
volumes:
- mysqldata:/var/lib/mysql
# initial database
# - has to be created first, e.g., by dumping the database from the prooductive system
- ./cwsvjudo.sql:/docker-entrypoint-initdb.d/cwsvjudo.sql
ports:
- 3306:3306
secrets:
- db_root_password
- db_password
# phpmyadmin
phpmyadmin:
image: phpmyadmin:latest
restart: always
depends_on:
- database
ports:
- 8080:80
environment:
# name of the host is the name of the db service started above! Why? I don't know!
- PMA_HOST=database
- PMA_PORT=3306
# - PMA_ARBITRARY=1
volumes:
# data storage for the db
mysqldata: {}
secrets:
db_root_password:
file: db_root_password.txt
db_password:
file: db_password.txt

View File

@@ -1,3 +1,4 @@
# @todo Needs helpfull comments.
server {
listen 80 default_server;
root /app/public;