0

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.

Raihanhbh
  • 77
  • 1
  • 10

3 Answers3

1

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.

nashter
  • 1,181
  • 1
  • 15
  • 33
0

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
Adiii
  • 54,482
  • 7
  • 145
  • 148
0

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 
zshan4444
  • 380
  • 3
  • 7
  • To access adminer use the following configuration as per the above docker-compose.yml file. URL : http://domain:4041 "system:"MySQL', "Server":"mysqldb","username":"xyz", "password":"pwd0123456789', "Database":"testdb" – zshan4444 Oct 29 '19 at 08:10