Connecting to Docker MySQL Container from Localhost
To interact with a MySQL instance running within a Docker container directly from your host machine, follow these steps:
Using docker-compose up
Since you have published port 3306 on your Docker host, you can connect to it from the host itself:
$> mysql -h 127.0.0.1 -P 3306 -u root
Using docker-compose run
If you are not using the docker-compose up command, include the --service-ports option to consider the port mapping section:
$> docker-compose run --service-ports db
Additional Considerations
$> mysql -h 127.0.0.1 -P 3306 -u root
The above is the detailed content of How to Connect to a Docker MySQL Container from Localhost?. For more information, please follow other related articles on the PHP Chinese website!