David.dev

How to install mariadb + phpmyadmin with docker-compose


Running mariadb + phpmyadmin is essential to run a number of web applications including django. A lot of django tutorials use postgresql but I found the
mariadb + phpmyadmin combination very user friendly to manage your database.

There are plenty of tutorials around but many are outdated so here is my quick guide to get you up and running:

Pre-requisites

You need to install docker and docker compose. You can find the documentation for Debian here and for Windows and Mac OS here.
For docker compose check the guide here

Create the docker-compose.yml file and run mariadb + phpmyadmin

With your editor of choice create a docker-compose.yml file using this model (pay attention to the variables to be set e.g. your password)

version: '3'

volumes:
  mariadb:
    driver: local

networks:
    db:
        driver: bridge

services:
  mariadb:
    image: mariadb:10.6
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: YOUR_ROOT_PASSWORD_HERE
      MYSQL_USER:  YOUR_MYSQL_USER_HERE 
      MYSQL_PASSWORD: YOUR_USER_PW_HERE
    expose:
        - "40000"
    ports:
        - "40000:3306"
    volumes:
     - mariadb:/var/lib/mysql
    networks:
      db:
              
  phpmyadmin:
    image: phpmyadmin
    restart: always
    expose:
      - "40001"
    ports:
      - "40001:80"
    environment:
      - PMA_HOST=mariadb
      - PMA_PORT=3306 
    networks:
      db:

after you save this file just run

sudo docker-compose up -d 

if you run into some issues e.g. phpmyadmin returns “cannot log into mysql server” or “packets out of order” like in this github issue

I suggest you to run

 sudo  docker-compose down -v

that should solve the issue.

This configuration will run MariaDB on port 40000 and PhpMyAdmin on port 40001 in your localhost only. For loading phpmyadmin locally you need to open an SSH tunnel like this:

ssh USERNAME@YOURDOMAIN.COM -L40001:127.0.0.1:40001

you can now load http://localhost:40001 and will be prompted with phpmyadmin where you can log in with the password you set in the docker-compose.yml file above.


75

made with ❤ī¸ by david.dev 2024 RSS Feed