› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
billgreen1
V2EX  ›  MySQL

怎么从 docker 中访问数据库?

  •  
  •   billgreen1 · Mar 16, 2017 · 6988 views
    This topic created in 3522 days ago, the information mentioned may be changed or developed.
    我在自己工作电脑上是可以访问公司数据库的,但是公司数据库应该是做了访问限制的, 估计是 IP.
    我现在在学习 docker ,在 docker 里面 pull 了一个 image.docker run xxxxx 之后,
    怎么从容器中访问数据库,就像从本机访问一样?
    10 replies  •  2017-03-17 12:51:42 +08:00
    billgreen1
    billgreen1
    OP
    Mar 16, 2017
    1
    PS , 数据库是 mysql
    dlllcs
    dlllcs
    Mar 16, 2017
    2
    @billgreen1 环境说清楚点。。。比如你数据库在哪,物理机还是容器上,等等
    sarices
    sarices
    Mar 16, 2017
    3
    ssh 转发吧
    Muninn
    Muninn
    Mar 16, 2017
    4
    一模一样没影响, docker 会继承你宿主机的对外网络的。你自己试了没,感觉服务端即使限制了 IP ,它获取到的也是你宿主机的 IP 啊。
    实在不行找 dba 改规则呗。
    to2false
    to2false
    Mar 16, 2017
    5
    本地直接 -p 端口映射下直接访问咯
    wweir
    wweir
    Mar 16, 2017 via Android
    6
    这年头求助都是不贴报错信息的吗?
    happywowwow
    happywowwow
    Mar 16, 2017
    7
    --network host

    https://docs.docker.com/engine/userguide/networking/#default-networks

    `The host network adds a container on the hosts network stack. You ’ ll find the network configuration inside the container is identical to the host.
    `
    paranoiagu
    paranoiagu
    Mar 16, 2017 via Android
    8
    我的 postgresql 就遇到 ip 问题了。后来是加了白名单解决的。
    znood
    znood
    Mar 17, 2017 via iPhone
    9
    7 楼的适合你,容器使用的主机网络
    Antidictator
    Antidictator
    Mar 17, 2017
    10
    @to2false 直接映射加一

    加一条,如果你部署的项目直接用的是局域网内的数据库,根本不用映射好吗,直接跑起来了吧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1844 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 03:57 · PVG 11:57 · LAX 19:57 · JFK 22:57
    ♥ Do have faith in what you're doing.