Apr 1, 2024 1 min read

How To Deploy MySQL And PHPMyAdmin With Docker

In this tutorial, we are going to run through the steps to set up a MySQL database coupled with PHPMyAdmin with Docker.

How To Deploy MySQL And PHPMyAdmin With Docker
Table of Contents

For many software engineers, their go-to relational database in most cases is MySQL. coupled with a web UI like PHPMyAdmin to view and also administer databases. In today's tutorial, we are going to run through the steps to set up a MySQL database coupled with PHPMyAdmin with Docker.

1. Docker Compose Script And Deployment

Our first step is to create a docker-compose.yml on our remote docker host where we are going to deploy the MySQL and PHPMyAdmin containers. Once created copy the script below to docker-compose.yml:

version: '3'

services:
  db:
    image: mysql:8.1
    ports:
      - 3306:3306
    restart: always
    container_name: mysql-db
    volumes:
      - /docker/gen-db01/sqldata:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: choose_password
      MYSQL_DATABASE: name-db
      MYSQL_USER: mysql_user
      MYSQL_PASSWORD: choose_password

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    container_name: my-phpmyadmin
    environment:
      PMA_HOST: db
    depends_on:
      - db
    ports:
      - "8880:80"

Once you copied the docker compose script run docker-compose up -d in your terminal to deploy the two containers. And once deployment is complete run docker ps to confirm that both the MySQL and PHPMyAdmin containers are running.

2. Login To PHPMyAdmin Web UI

Once confirmed that both containers are running navigate to http://<docker_host_ip>:8880 and login to the PHPMyAdmin web UI with the MySQL user created above.

PHPMyAdmin Login Web UI

Conclusion

In conclusion, there are many open-source relational database management software that you can deploy with web UI solutions. If you enjoyed this article consider signing up for our newsletter and don't forget to share it with people who would find it useful. Leave a comment below with a tutorial you would like us to cover.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Opensource Geeks.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.