技术

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

微信扫一扫,分享到朋友圈

【爬坑日记】MAC使用docker搭建php开发环境
收藏 0 0

生命不息,爬坑不止

絮叨一下

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

等了不到20分钟之后,进入宝塔界面,http://127.0.0.1:8888/,命令行都有。然后根据需要安装环境。

我的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提交的时候不要提交到代码库哦

展开阅读全文
半拉子前端的自留地,发际线逐渐后移的抠脚大叔!

【爬坑日记】Mac Mysql出现this is incompatible with sql_mode=only_full_group_by

上一篇

网站准备迁移到阿里云oss上,要做什么

下一篇

你也可能喜欢

发表评论

您的电子邮件地址不会被公开。 必填项已用 * 标注

提示:点击验证后方可评论!

插入图片

体验小程序

标签地图

分类

EA PLAYER &

历史记录 [ 注意:部分数据仅限于当前浏览器 ]清空

      00:00/00:00

      微信扫一扫

      微信扫一扫