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
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3