skip to Main Content

I want to spawn MySQL & PHPMyAdmin docker containers. Mysql container can be accessed via 3306 port & PHPMyAdmin can be accessed through 8280 port.

My question is, how a PHP application can be configured to access the MySQL docker container on 3306 port
and the PHPMyAdmin can be configured for MySQL.

Thanks.

3

Answers


  1. You can use the offical image for MySQL and PHPMyAdmin.

    version: '3.1'
    
    services:
    
      db:
        image: mysql
        command: --default-authentication-plugin=mysql_native_password
        environment:
          MYSQL_ROOT_PASSWORD: example
    
      phpmyadmin:
        image: phpmyadmin/phpmyadmin
        ports:
          - 8081:80
    
    

    To access it from php container, just add your php container in the docker-compose, so the connection string should be like

    host:db
    user: root
    pass: example
    
    Login or Signup to reply.
  2. You can use Adminer a database management tool.

    You need the below configuration in docker-compose.yml for Mysql and adminer.

     mysqldb:
      container_name: mysqldb
      image: mysql
      restart: always
      environment:
      - MYSQL_USER= 'xyz'
      - MYSQL_PASSWORD='pwd0123456789'
      - MYSQL_DB= 'testdb'
    networks:
      - main
    
    adminer: 
     container_name: adminer
     image: adminer
     restart: always
     ports:
      - 4041:8080
     networks:
      - main-network
     depends_on:
      - mysqldb 
    
    Login or Signup to reply.
  3. Start MySQL server

    docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -d mysql
    

    Start phpAdmin with link to mysql container

    docker run --name myadmin -d --link mysql:db -p 8080:80 phpmyadmin/phpmyadmin
    

    PHPAdmin application will be serving on localhost:80. MySQL credentials will be root/password.

    We can now use docker-compose for this solution which is more portable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search