Giter Site home page Giter Site logo

docker-mariadb-phpmyadmin's Introduction

Docker running MariaDB with PHPMyAdmin

Overview

  1. Install prerequisites

    Before installing project make sure the following prerequisites have been met.

  2. Clone the project

    We’ll download the code from its repository on GitHub.

  3. Run the application

    By this point we’ll have all the project pieces in place.

  4. Use Makefile [Optional]

    When developing, you can use Makefile for doing recurrent operations.

  5. Use Docker Commands

    When running, you can use docker commands for doing recurrent operations.


Install prerequisites

To run the docker commands without using sudo you must add the docker group to your-user:

sudo usermod -aG docker your-user

For now, this project has been mainly created for Unix (Linux/MacOS). Perhaps it could work on Windows.

All requisites should be available for your distribution. The most important are :

Check if docker-compose is already installed by entering the following command :

which docker-compose

Check Docker Compose compatibility :

The following is optional but makes life more enjoyable :

which make

On Ubuntu and Debian these are available in the meta-package build-essential. On other distributions, you may need to install the GNU C++ compiler separately.

sudo apt install build-essential

Images to use

You should be careful when installing third party web servers such as MySQL or Nginx.

This project use the following ports :

Server Port
MariaD 4000
PHPMyAdmin 4001

Clone the project

To install Git, download it and install following the instructions :

git clone https://github.com/r0drigocarvalho/docker-mariadb-phpmyadmin

Go to the project directory :

cd docker-mariadb-phpmyadmin

Project tree

.
├── Makefile
├── README.md
├── data
│   └── db
│       ├── dumps
│       └── mysql
├── doc
├── docker-compose.yml
└── web
    ├── app
    └── composer.json

Run the application

  1. Start the application :

    docker-compose up -d

    Please wait this might take a several minutes...

    docker-compose logs -f # Follow log output
  2. Open your favorite browser :

  3. Stop and clear services

    docker-compose down -v

Use Makefile

When developing, you can use Makefile for doing the following operations :

Name Description
clean Clean directories for reset
composer-up Update PHP dependencies with composer
docker-start Create and start containers
docker-stop Stop and clear all services
logs Follow log output
mysql-dump Create backup of all databases
mysql-restore Restore backup of all databases

Examples

Start the application :

make docker-start

Show help :

make help

Handling database

MySQL shell access

docker exec -it mysql bash

and

mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"

Creating a backup of all databases

mkdir -p data/db/dumps
source .env && docker exec $(docker-compose ps -q mariadb) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "data/db/dumps/db.sql"

Restoring a backup of all databases

source .env && docker exec -i $(docker-compose ps -q mariadb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/db.sql"

Creating a backup of single database

Notice: Replace "YOUR_DB_NAME" by your custom name.

source .env && docker exec $(docker-compose ps -q mariadb) mysqldump -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" --databases "$MYSQL_DATABASE" > "data/db/dumps/"$MYSQL_DATABASE".sql"

Restoring a backup of single database

source .env && docker exec -i $(docker-compose ps -q mariadb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/"$MYSQL_DATABASE".sql"

Connecting MySQL from PDO

<?php
    try {
        $dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';
        $pdo = new PDO($dsn, 'dev', 'dev');
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
?>

Help us

Any thought, feedback or (hopefully not!)

docker-mariadb-phpmyadmin's People

Contributors

r0drigocarvalho avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.