Answer the question
In order to leave comments, you need to log in
How to access mysql db outside container?
Working with docker-compose
web:
image: igontarev/php-server
ports:
- "80:80"
- "443:443"
volumes:
- ./www:/var/www
- ./sites:/etc/nginx/sites-enabled
- ./logs/nginx:/var/log/nginx
- ./logs/php:/var/log/php
- ./cron:/etc/cron.d
- ./supervisor:/etc/supervisor/conf.d
- ./letsencrypt:/etc/letsencrypt
- ./lib/letsencrypt:/var/lib/letsencrypt
db:
image: mysql:5.7
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=nimda2017
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
30b0b955fdca igontarev/php-server "/usr/bin/supervisord" 7 seconds ago Up 6 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp docker_web_1
1d7ad0ed6081 mysql:5.7 "docker-entrypoint..." 7 seconds ago Up 6 seconds 0.0.0.0:3306->3306/tcp docker_db_1
Answer the question
In order to leave comments, you need to log in
It works without additional settings 127.0.0.1
, here is a working scenario:
docker run --name db_test \
-e MYSQL_DATABASE=test \
-e MYSQL_ROOT_PASSWORD=root \
-p 3306:3306 \
-d mysql:5.5
mysql-client
, you can use any client, use the console, roll up the dams:MYSQL_PWD=root mysql \
-u root -h 127.0.0.1 \
--init-command="SET SESSION FOREIGN_KEY_CHECKS=0;" \
test < dump.sql
MYSQL_PWD=root mysqldump \
-u root -h 127.0.0.1 \
--compact \
--add-drop-table \
--extended-insert=FALSE \
test_moco_core > dump.sql
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question