How can we access PHPMyAdmin?
aaravrana opened this issue · 1 comments
How can we access phpmyadmin using browser to access the database? Can we add it to the docker image itself?
Thanks,
aR
Yes, there are two ways of doing this. Either install it on existing docker images repo or download it along with other docker images.
Manually Download
To download the phpmyadmin image, simply run below command and link it to your MySql container. More info - https://docs.phpmyadmin.net/en/latest/setup.html#installing-using-docker
docker pull phpmyadmin/phpmyadmin
Using docker-compose
In order to install with rest of docker images, you may include the below code in your docker-compose.yml
file as shown below:
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
links:
- mysql:mysql
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
MYSQL_USER: "${DB_USERNAME}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
restart: always
networks:
- backend
Please note I don't want to add many services to my existing branch because I want to keep it lightweight. After adding the above code, your docker-compose.yml
file should be:
version: "3.2"
services:
php:
build:
context: './php/'
args:
PHP_VERSION: ${PHP_VERSION}
networks:
- backend
volumes:
- ${PROJECT_ROOT}/:/var/www/html/
container_name: php
apache:
build:
context: './apache/'
args:
APACHE_VERSION: ${APACHE_VERSION}
depends_on:
- php
- mysql
networks:
- frontend
- backend
ports:
- "80:80"
volumes:
- ${PROJECT_ROOT}/:/var/www/html/
container_name: apache
mysql:
image: mysql:${MYSQL_VERSION:-latest}
restart: always
ports:
- "3306:3306"
volumes:
- data:/var/lib/mysql
networks:
- backend
environment:
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USERNAME}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
container_name: mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
links:
- mysql:mysql
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
MYSQL_USER: "${DB_USERNAME}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
restart: always
networks:
- backend
networks:
frontend:
backend:
volumes:
data:
Now you need to rebuild the images again and you will be able to access phpmyadmin on your localhost using http://localhost:8080/ URL.
Hope it helps!