惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tor Project blog
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Last Week in AI
Last Week in AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker
博客园 - 三生石上(FineUI控件)
量子位
腾讯CDC
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
Recorded Future
Recorded Future
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
Simon Willison's Weblog
Simon Willison's Weblog
Cloudbric
Cloudbric
Project Zero
Project Zero
SecWiki News
SecWiki News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Latest news
Latest news
Schneier on Security
Schneier on Security
小众软件
小众软件
U
Unit 42
Y
Y Combinator Blog
Help Net Security
Help Net Security
Vercel News
Vercel News
月光博客
月光博客
WordPress大学
WordPress大学
C
CERT Recently Published Vulnerability Notes
Google Online Security Blog
Google Online Security Blog
T
Tenable Blog
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale

博客园 - 斌哥tobin

Go工程选择开源分库分表中间件可用性测试 Golang解决fatal error: all goroutines are asleep - deadlock! Laravel Model查询结果的3种存储格式内存占用对比 Laravel配置Route调用artisan 研究微信红包分配算法之Golang版 解决IDEA提示Untrusted Server's certificate 证书不可用( Server's certificate is not trusted ) select * 和 select 字段的速度对比 Docker镜像拉取失败或超时的解决办法:添加国内镜像 VirtualBox虚拟CentOS7共享文件夹 Windows7用VirtualBox虚拟Ubuntu共享文件夹的终极方式 PhpStorm添加PHP代码规范检查CodeSniffer(phpcs)和PHP代码静态分析工具Mess Detector(phpmd) php的三个常用判断函数 php计算字符串长度 mac brew 安装php扩展报错:parent directory is world writable but not sticky Mac iTerm2命令行快捷操作 System.Web.AspNetHostingPermission 类型的权限已失败 优化phpstorm运行卡顿问题! composer [ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist - 斌哥tobin nginx1.8安装nginx_concat_module及400错误解决办法
php连接docker运行的mysql,显示(HY000/2002): Connection refused的解决办法
斌哥tobin · 2018-01-16 · via 博客园 - 斌哥tobin

2018-01-16 22:23  斌哥tobin  阅读(8014)  评论()    收藏  举报

  • php要连接docker中运行的mysql是不能用localhost, 127.0.0.1来连接的,因为每个docker运行容器的localhost 127.0.0.1都是自己容器本身,不是mysql容器,需要修改成母机 IP,或者是mysql容器名称

  • 比如有如下的docker-compose.yml

version: '3'

services:
  mysql:
#   build: ./mysql
    image: daocloud.io/library/mysql:5.7.20
    volumes:
      - ./mysql/conf:/etc/mysql
      - ./mysql/data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
    ports:
      - "3306:3306"
    networks:
      - lnmp

  php54:
    build: ./php54
#  # 使用宿主:容器 (HOST:CONTAINER)格式或者仅仅指定容器的端口(宿主将会随机选择端口)都可以
#  # 开放9000端口
    ports:
      - "9005:9000"
#  # 此处实现文件夹代码目录映射
    volumes:
      - ../:/data
      - ./php54/hosts:/etc/hosts
      - ./php54/etc/php/php.ini:/usr/local/etc/php/php.ini
      - ./php54/etc/php-fpm.conf:/usr/local/etc/php-fpm.conf
    links:
      - mysql
    privileged: true
    networks:
      - lnmp
  nginx:
    build: ./nginx
  # 此处实现文件夹代码目录映射
    volumes:
      - ../:/data
      - ./php54/hosts:/etc/hosts
    links:
      - php54:php54
    privileged: true
    ports:
      - "80:80"
    networks:
      - lnmp

networks:
  lnmp:
    driver: bridge

  • php中连接的 mysql 地址就是 mysql就可以连接了,不用 localhost 或127.0.0.1