生命不息,爬坑不止
絮叨一下
使用mamp开发php重启了下机器,就崩了,重新下载安装以后问题依旧。
这时候想到使用docker作为开发环境的方案,以前简单尝试过,今天没法干活了,干!
电脑本身就安装了docker,只是没怎么用。
// 先来一个服务器镜像
git pull centos
// 启动一个容器,绑定自己用的端口,映射项目目录,还有宝塔的目录,方便
docker run -i -t -d --name baota -p 20:20 -p 21:21 -p 80:80 -p 443:443 -p 9000:9000 -p 8888:8888 --privileged=true -v /Users/tingno/Documents/www:/www centos
// 进入容器
docker exec -it baota /bin/bash
// 安装宝塔
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
我的mysql之前是直接使用的原生的mac上直接安装的版本,数据都在这里面,就不用服务器上安装了,所以用的只是安装了 nginx和php7.2两个服务。
安装完以后加应用,调目录,配置nginx。
一通配置之后,问题来了
问题:dockor如何访问宿主机mysql
看到网上问题,配置 root@%的方案,不管用。
解决
在docker里面使用 docker.for.mac.host.internal:3306 就可以访问宿主机Mac上面的mysql了。
DNS name docker.for.mac.host.internal should be used instead of docker.for.mac.localhost (still valid) for host resolution from containers, since since there is an RFC banning the use of subdomains of localhost. See https://tools.ietf.org/html/draft-west-let-localhost-be-localhost-06.
同样的,在Windows下面也有类似的便捷地址用来访问宿主机器。如下:
On Mac and Windows it is possible to use docker.for.mac.host.internal (replaces docker.for.mac.localhost) and docker.for.win.host.internal (replaces docker.for.win.localhost) inside container.
总结
直接在源码数据库配置文件中,将主机地址改成 docker.for.mac.host.internal ,记得git提交的时候不要提交到代码库哦
本文由 听否 发布在 听-笔记,转载此文请保持文章完整性,并请附上文章来源(听-笔记)及本页链接。
原文链接:https://www.tingno.com/archives/515