简体   繁体   English

访问在Docker容器中运行的数据库?

[英]Accessing database that is running inside a docker container?

I have a MariaDB up and running in a Docker container. 我有一个MariaDB在Docker容器中运行。 I want to know how to connect to it from an app running locally (not) in the docker container. 我想知道如何从docker容器中本地运行(而不是运行)的应用程序连接到它。 How can I open up access? 如何打开访问权限?

your MariaDB container must publish ports, and you will connect using those ports. 您的MariaDB容器必须发布端口,然后您将使用这些端口进行连接。 See for example http://amattn.com/p/installing_maria_db_mysql_with_docker.html 参见例如http://amattn.com/p/installing_maria_db_mysql_with_docker.html

the port 3306 in the container will be mapped to a port on the host, and you will connect to that port. 容器中的端口3306将映射到主机上的端口,您将连接到该端口。

when you call docker run to start your container you can bind a specific port like this 当您调用docker run启动容器时,您可以像这样绑定特定端口

docker run -p your_port:3306

this will make your container accessible on docker_host_ip:your_port and the docker service will take care of forwarding the connection to the right container at the port 3306 这将使您的容器在docker_host_ip:your_port上可访问,并且docker服务将负责将连接转发到端口3306处的正确容器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM