mac docker php mysql_【爬坑日记】MAC使用docker搭建php开发环境

生命不息,爬坑不止

絮叨一下

使用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值