MySQL on Docker

Install MySQL & PhpMyAdmin on Docker for local development work.
We need to create following docker compose file for Portainer. 

version: '3.4'

services:

  application_db:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - db-data:/var/lib/mysql
    ports:
      - 3306:3306

  help_phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_ARBITRARY: 1
      UPLOAD_LIMIT: 300M
    ports:
      - ${PUBLIC_PMA_PORT}:80
volumes:
  db-data:  

And we need to provide the following variable details –

MYSQL_DATABASE=<YOUER_DB_NAME>
MYSQL_USER=<YOUER_DB_USER>
MYSQL_PASSWORD=<YOUER_DB_PASSWORD>
MYSQL_ROOT_PASSWORD=<YOUER_DB_ROOT_PASSWORD>
PUBLIC_PMA_PORT=8801

Points to remember –
we are exposing Database port. So database is accessible via local machine and phpMyAdmin.

Known Exceptions:

If you face any issues like –
mysqli::real_connect(): (HY000/1130): Host ‘10.0.4.4’ is not allowed to connect to this MySQL server” then please add the following parameter –
MYSQL_ROOT_HOST: ‘%’
So, the environment would be –

environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_ROOT_HOST: '%'


Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *