Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»General Articles»Docker-compose for MySQL with phpMyAdmin

    Docker-compose for MySQL with phpMyAdmin

    RahulBy RahulJuly 3, 20202 Mins Read

    Docker-compose is an useful utility for managing multi-container docker applications. In our previous tutorial, I had discussed about the keep persistent data of MySQL docker containers using Docker volumes. Once you launched a MySQL container can be connect via terminal directly. But the phpMyAdmin lovers may need the web interface for managing databases.

    In this tutorial, you will learn to launch MySQL Docker containers along with phpMyAdmin docker container using docker-compose command.

    Prerequisites

    This guide assumes that you have already done the followings:

    1. You have installed Docker service on your System
    2. Also, have configured docker-compose utility on your system

    How to Create MySQL with phpMyAdmin Docker Container

    phpMyAdmin is an most popular web application for managing MySQL database servers. In this tutorial, we just use an example of Docker container for MySQL and phpMyAdmin.

    So first create a docker-compose.yml file on your system with the following content.

    docker-compose.yml:

    Shell
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    version: '3'
    services:
      db:
        image: mysql:5.7
        container_name: db
        environment:
          MYSQL_ROOT_PASSWORD: my_secret_password
          MYSQL_DATABASE: app_db
          MYSQL_USER: db_user
          MYSQL_PASSWORD: db_user_pass
        ports:
          - "6033:3306"
        volumes:
          - dbdata:/var/lib/mysql
      phpmyadmin:
        image: phpmyadmin/phpmyadmin
        container_name: pma
        links:
          - db
        environment:
          PMA_HOST: db
          PMA_PORT: 3306
          PMA_ARBITRARY: 1
        restart: always
        ports:
          - 8081:80
    volumes:
      dbdata:

    Save you file and close it.

    Next, run the following command to create Docker containers using the docker-compose.yml configuration file.

    docker-compose up -d
    

    The above command will launch two Docker containers, one for MySQL database server and one for phpMyAdmin. Also a data volume will be created, which is attached with MySQL container to make data persistent.

    Now, access the phpMyAdmin using the web browser. I am running this example on my local machine. So used host as localhost with port 8081 defined in docker compose configuration. You need to change localhost with your server ip address to access it remotely.

    http://localhost:8081
    

    Docker compose for mysql and phpmyadmin

    Conclusion

    In this tutorial, you have learned to launch a MySQL docker container with a phpMyAdmin. Which help help you to manage databases on MySQL docker container.

    Docker Docker-compose MySQL phpmyadmin
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Ionic on Fedora 34/33/32
    Next Article How To Find Files Modified in Last 30 Days in Linux

    Related Posts

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    (Resolved) – ReactJS 404 Error on Page Reload

    2 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How To Install MySQL Server on Ubuntu 22.04

    Updated:April 6, 20224 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    3 Comments

    1. ganesh on April 27, 2021 10:48 am

      how make like localhost/phpmyadmin to display phpmyadim

      Reply
    2. Nicholas on December 16, 2020 5:25 pm

      Hi Rahul, thanks for this… I am wondering how you create the MySQL connection URL from the environment variables you have listed from lines 7-13 in the docker-compose.yml file? does port take the place of in the connection URL?

      Reply
      • Rahul on December 16, 2020 5:34 pm

        Here port is used to bind host machine port (6033) to bind mysql port (3306) running in container.

        If you are connecting docker container from another docker container, no need to define port. It will connect over default port.

        But when connecting mysql from host machine use 6033 port to connect mysql running under container.

        Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.