Hello
I am a beginner.
I have 3 container up : app (laravel) , webserver (nginx) , db (mysql)
I want to work with mysql from host.
It means I want to connect from localhost\phpmyadmin to mysql in the container. But I get error 404 not found or unable to cionnect.
(for example I can connect to app from host by localhost address . But in phpmyadmin I can not ).
Why it can not find the mysql ?
Thank you
You need to publish/map the port of the mysql container to the host. If you share your docker run command or docker-compose.yml, we can help you further.
Thenk you. for replying.
If you explain more, it will be great.
This is my docker-compose :
version: ‘3’
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- “80:80”
- “443:443”
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- “3306:3306”
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: 12345@6
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
This looks ok. Maybe you’re configuring mysql to only listen to local host through ./mysql/my.cnf
. What’s the content of that file?
This is the content of my.cnf
[mysqld]
general_log = 1
general_log_file = /var/lib/mysql/general.log
and this is the result of : docker inspect db
docker_inspect_db_output.txt (10.5 KB)
I tried your setup locally with phpmyadmin running in a container and it worked for me. I’m assuming it’s on phpmyadmin’s end. You can try running it in a container. If you need it on the host look in the phpmyadmin configuration file (config.inc.php
) for the connection settings to mysql.
Here’s a working docker-compose.yml
version: "3.7"
services:
db:
image: mysql:5.7.22
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: 12345@6
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./my.cnf:/etc/mysql/my.cnf
networks:
- app-network
pma:
image: phpmyadmin/phpmyadmin
ports:
- "8080:80"
networks:
- app-network
environment:
MYSQL_ROOT_PASSWORD: 12345@6
networks:
app-network:
driver: bridge
volumes:
dbdata:
driver: local
Thanks .
It works.
I was wrong to insist on running mysql from host .
As you say , I made a container for mysql and It work very easy and rapid.
Thank you