Skip to content

Instantly share code, notes, and snippets.

@ashutoshsahoo
Last active February 9, 2025 16:37
Show Gist options
  • Save ashutoshsahoo/515398a366e982e6d8c4c95fe5628089 to your computer and use it in GitHub Desktop.
Save ashutoshsahoo/515398a366e982e6d8c4c95fe5628089 to your computer and use it in GitHub Desktop.
MySQL and PhpMyAdmin Docker Compose Setup

MySQL and PhpMyAdmin Docker Compose Setup

Docker compose file

Create a file named docker-compose.yml and add following content into it.

services:
  mysqldb:
    image: mysql:8
    container_name: mysqldb
    environment:
      MYSQL_ROOT_PASSWORD: my_secret_password
      MYSQL_DATABASE: app_db
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_user_pass
    ports:
      - "3306:3306"
    volumes:
      - dbdata:/var/lib/mysql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    links:
      - mysqldb
    environment:
      PMA_HOST: mysqldb
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    restart: always
    ports:
      - 8081:80
volumes:
  dbdata:

Start Database

docker-compose up -d

Access MySQL

  • JDBC Connection string without username and password : jdbc:mysql://localhost:3306/app_db
  • JDBC Connection string with username and password : jdbc:mysql://db_user:db_user_pass@localhost:3306/app_db
  • Database Connection properties
    • Host : localhost
    • port : 3306
    • database name : app_db
    • username : db_user
    • password : db_user_pass

Access phpMyAdmin

  • Open http://localhost:8081
  • Login with username root and password my_secret_password, leave server field empty.

Stop & Remove Database

docker-compose down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment