virtualbox php mac,详解mac下通过docker搭建LEMP环境

在mac下通过docker搭建LEMP环境境

1.安装virtualbox。由于docker是在lxc环境的容器

2.安装boot2docker,用于与docker客户端通讯

> brew update

> brew install docker

> brew install boot2docker

3.初始化boot2docker,也就是在virtualbox上安装一个docker的host环境

boot2docker init

此时会下载一个镜像

4.启动虚拟机host

:~$ boot2docker up

Waiting for VM and Docker daemon to start...

....................ooo

Started.

To connect the Docker client to the Docker daemon, please set:

export DOCKER_HOST=tcp://192.168.59.103:2375

unset DOCKER_CERT_PATH

这样host环境就启动起来了,根据提示设置环境变量

export DOCKER_HOST=tcp://192.168.59.103:2375

后boot2docker就能与host环境的docker客户端连接了

5.连接host环境的docker客户端

MacBook-Pro:~$ boot2docker ssh

## .

## ## ## ==

## ## ## ## ===

/""""""""""""""""\___/ ===

~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~

\______ o __/

\ \ __/

\____\______/

_ _ ____ _ _

| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __

| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|

| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |

|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|

boot2docker with VirtualBox guest additions version 4.3.14

boot2docker: 1.2.0

master : e75396e - Fri Aug 22 06:03:48 UTC 2014

docker@boot2docker:~$

这样我们就成功登录virtualbox中的host环境,便可以进行docker操作了

安装nginx,php,mysql,基于ubuntu14:04,以下我是通过Dockerfile安装的

6.生成mysql镜像

Dockerfile

# LEMP stack as a docker container

FROM ubuntu:14.04

MAINTAINER Daniel Watrous

#ENV http_proxy http://proxy.example.com:8080

#ENV https_proxy https://proxy.example.com:8080

RUN apt-get update

RUN apt-get -y upgrade

# seed database password

COPY mysqlpwdseed /root/mysqlpwdseed

RUN debconf-set-selections /root/mysqlpwdseed

RUN apt-get -y install mysql-server

RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf

RUN /usr/sbin/mysqld & \

sleep 10s &&\

echo "GRANT ALL ON *.* TO admin@'%' IDENTIFIED BY 'secret' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql -u root --password=secret &&\

echo "create database test" | mysql -u root --password=secret

# persistence: http://txt.fliglio.com/2013/11/creating-a-mysql-docker-container/

EXPOSE 3306

CMD ["/usr/bin/mysqld_safe"]

mysqlpwdseed

mysql-server mysql-server/root_password password secret

mysql-server mysql-server/root_password_again password secret

进入mysql的Dockefile然后生成一个mysql镜像

docker build -t "local/mysql:v1" .

成功后用

docker images

查看已生成的镜像

运行mysql镜像,生成一个容器

docker run -d --name mysql local/mysql:v1

运行起来后,可以用

boot2docker:~$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

c2332dcad7ca local/mysql:v1 "/usr/bin/mysqld_saf 26 hours ago Up 2 seconds 3306/tcp mysql,nginx/mysql

来查看正在运行的容器

7.生成nginx,php ,这两个用一个dockerfile生成一个镜像

dockerfile

# LEMP stack as a docker container

FROM ubuntu:14.04

MAINTAINER Daniel Watrous

ENV http_proxy http://proxy.example.com:8080

ENV https_proxy https://proxy.example.com:8080

# install nginx

RUN apt-get update

RUN apt-get -y upgrade

RUN apt-get -y install nginx

RUN echo "daemon off;" >> /etc/nginx/nginx.conf

RUN mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak

COPY default /etc/nginx/sites-available/default

# install PHP

RUN apt-get -y install php5-fpm php5-mysql

RUN sed -i s/\;cgi\.fix_pathinfo\s*\=\s*1/cgi.fix_pathinfo\=0/ /etc/php5/fpm/php.ini

# prepare php test scripts

RUN echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php

ADD wall.php /usr/share/nginx/html/wall.php

# add volumes for debug and file manipulation

VOLUME ["/var/log/", "/usr/share/nginx/html/"]

EXPOSE 80

CMD service php5-fpm start && nginx

default 一个默认的nginx配置文件

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;

index index.php index.html index.htm;

server_name localhost;

location / {

try_files $uri $uri/ =404;

}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

location ~ \.php$ {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

}

}

wall.php 一个用来测试连接mysql的测试文件

// database credentials (defined in group_vars/all)

$dbname = "test";

$dbuser = "admin";

$dbpass = "secret";

$dbhost = "mysql";

// query templates

$create_table = "CREATE TABLE IF NOT EXISTS `wall` (

`id` int(11) unsigned NOT NULL auto_increment,

`title` varchar(255) NOT NULL default '',

`content` text NOT NULL default '',

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8";

$select_wall = 'SELECT * FROM wall';

// Connect to and select database

$link = mysql_connect($dbhost, $dbuser, $dbpass)

or die('Could not connect: ' . mysql_error());

echo "Connected successfully\n
\n";

mysql_select_db($dbname) or die('Could not select database');

// create table

$result = mysql_query($create_table) or die('Create Table failed: ' . mysql_error());

// handle new wall posts

if (isset($_POST["title"])) {

$result = mysql_query("insert into wall (title, content) values ('".$_POST["title"]."', '".$_POST["content"]."')") or die('Create Table failed: ' . mysql_error());

}

// Performing SQL query

$result = mysql_query($select_wall) or die('Query failed: ' . mysql_error());

// Printing results in HTML

echo "

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

echo "\t

\n";

foreach ($line as $col_value) {

echo "\t\t

$col_value\n";

}

echo "\t

\n";

}

echo "

\n";

// Free resultset

mysql_free_result($result);

// Closing connection

mysql_close($link);

?>

Title:

Message:

把这三个文件放在同一目录

进入目录

利用dockerfile生成镜像

docker build -t "local/nginx:v1" .

生成成功后查看句是你

boot2docker:~$ docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

local/nginx v1 9489872e2ebb 25 hours ago 250 MB

local/mysql v1 b70d2e0f7f9c 26 hours ago 351.1 MB

ubuntu 14.04 9bd07e480c5b 3 days ago 192.7 MB

运行

docker run -d -p 80:80 --link mysql:mysql --name nginx local/nginx:v1

这时通过查看正在运行的容器

boot2docker:~$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

52e430b58579 local/nginx:v1 "/bin/sh -c 'service 21 hours ago Up 3 seconds 0.0.0.0:80->80/tcp nginx

c2332dcad7ca local/mysql:v1 "/usr/bin/mysqld_saf 26 hours ago Up 11 minutes 3306/tcp mysql,nginx/mysql

就可以看到nginx和mysql两个运行中的容器,其中nginx通过link连接到了mysql容器,

通过

--link mysql:mysql

命令,把mysql容器的地址加入到了nginx父容器的host文件中,此后,通过访问别名mysql,就可以访问到数据库了。

浏览器访问:192.168.59.103/wall.php,就可访问刚搭好的web服务器

8.持载目录到容器中

我们希望持载一个本地目录到容器中,以后存放可能需要修改的web内容,这里我们通过

-v /Users/lyc/web:/usr/share/nginx/html

把的本地目录到容器中,存放web目录内容,这样就可以把wall.php之类的web文件放在/Users/lyc/web目录,供容器访问

但是因为mac环境下host主机为virtualbox,因此我们先要绑定mac下的目录到虚拟机中

首先停止boot2docker

> boot2docker down

然后

> curl http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso > ~/.boot2docker/boot2docker.iso

> VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users

> boot2docker up

重新连docker后

先删除原先停止的容器

docker rm mysql

docker rm nginx

启动容器时挂载我们的目录到nginx的目录中

docker run -d -p 3306:3306 --name mysql mysqldb

docker run -d -p 80:80 -v /Users/lyc/web:/usr/share/nginx/html --link mysql:mysql --name nginx local/nginx:v1

这样就可以修改/Users/lyc/web中的内容来更新/usr/share/nginx/html了

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388696.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SpringBoot项目打war包部署Tomcat教程

一、简介 正常来说SpringBoot项目就直接用jar包来启动&#xff0c;使用它内部的tomcat实现微服务&#xff0c;但有些时候可能有部署到外部tomcat的需求&#xff0c;本教程就讲解一下如何操作 二、修改pom.xml 将要部署的module的pom.xml文件<packaging>节点设置为war <…

在VS2005中使用添加变量向导十分的

在VS2005中使用添加变量向导十分的方便&#xff0c;但是如何手动添加呢。可以分为2步&#xff1a; 1. 在控件对应的类的头文件中添加相应的变量声明&#xff08;如&#xff1a;CString m_strResult&#xff09; 2. 在类的实现文件中的DoDataExchange(CDataExchange* pDX)函数…

关于如何使用xposed来hook微信软件

安卓端 难点有两个 收款码的生成和到帐监听需要源码加 2442982910转载于:https://www.cnblogs.com/ganchuanpu/p/10220705.html

GitHub动作简介

GitHub Actions can be a little confusing if you’re new to DevOps and the CI/CD world, so in this article, we’re going to explore some features and see what we can do using the tool.如果您是DevOps和CI / CD领域的新手&#xff0c;那么GitHub Actions可能会使您…

java returnaddress,JVM之数据类型

《Java虚拟机规范》阅读笔记-数据类型1.概述Java虚拟机的数据类型可分为两大类&#xff1a;原始类型(Primitive Types&#xff0c;也称为基本类型)和引用类型(Reference Types)。Java虚拟机用不同的字节码指令来操作不同的数据类型[1] 。2.原始类型原始类型是最基本的元素&…

C# matlab

编译环境&#xff1a;Microsoft Visual Studio 2008版本 9.0.21022.8 RTMMicrosoft .NET Framework版本 3.5已安装的版本: ProfessionalMicrosoft Visual Basic 2008 91986-031-5000002-60050Microsoft Visual Basic 2008Microsoft Visual C# 2008 91986-031-5000002-60050…

洛谷P3273 [SCOI2011] 棘手的操作 [左偏树]

题目传送门 棘手的操作 题目描述 有N个节点&#xff0c;标号从1到N&#xff0c;这N个节点一开始相互不连通。第i个节点的初始权值为a[i]&#xff0c;接下来有如下一些操作&#xff1a; U x y: 加一条边&#xff0c;连接第x个节点和第y个节点A1 x v: 将第x个节点的权值增加vA2 x…

基于容器制作镜像

一。镜像基础 一。基于容器制作镜像 1. 查看并关联运行的容器 [ghlocalhost ~]$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4da438fc9a8e busybox …

照顾好自己才能照顾好别人_您必须照顾的5个基本数据

照顾好自己才能照顾好别人I am pretty sure that on your data journey you came across some courses, videos, articles, maybe use cases where someone takes some data, builds a classification/regression model, shows you great results, you learn how that model wo…

matlab数字仿真实验,DVR+备用电源自动投入的MATLAB数字仿真实验仿真实验

一、动态电压恢复器(DVR)的数字仿真实验动态电压恢复器(Dynamic Voltage Restorer&#xff0c;DVR)是一种基于电力电子技术的串联补偿装置&#xff0c;通常安装在电源与敏感负荷之间&#xff0c;其作用在于&#xff1a;保证电网供电质量&#xff0c;补偿供电电网产生的电压跌落…

c#,xp系统,Matlab6.5

编译环境&#xff1a;c#&#xff0c;xp系统&#xff0c;Matlab6.5 新建一个窗体项目&#xff0c;添加matlab引用。 然后试了四种方式调用matlab&#xff1a; 第一种 view plaincopy to clipboardprint?MLApp.MLAppClass matlab new MLApp.MLAppClass(); matlab.Visible 1;…

java script 对象

java script 对象 1.创建方式 1&#xff09;通过字面量的形式创建 例&#xff1b;var stt{x:1,y:2,y:3}; 或&#xff1b;var stt{ x:1, y:2, for:3 } 注意关键字必须放到引号中间 2&#xff09;通过new创建对象 例&#xff1a;var new stt(); stt.name 小鱼; stt.age 20…

认识数据分析_认识您的最佳探索数据分析新朋友

认识数据分析Visualization often plays a minimal role in the data science and model-building process, yet Tukey, the creator of Exploratory Data Analysis, specifically advocated for the heavy use of visualization to address the limitations of numerical indi…

架构探险笔记10-框架优化之文件上传

确定文件上传使用场景 通常情况下&#xff0c;我们可以通过一个form&#xff08;表单&#xff09;来上传文件&#xff0c;就以下面的“创建客户”为例来说明&#xff08;对应的文件名是customer_create.jsp&#xff09;&#xff0c;需要提供一个form&#xff0c;并将其enctype属…

matlab飞行数据仿真,基于MATLAB的飞行仿真

收稿日期: 2005 - 05 - 15   第 23卷  第 06期 计  算  机  仿  真 2006年 06月    文章编号: 1006 - 9348 (2006) 06 - 0057 - 05 基于 MATLAB的飞行仿真 张镭 ,姜洪洲 ,齐潘国 ,李洪人 (哈尔滨工业大学电液伺服仿真及试验系统研究所 ,黑龙江 哈尔滨 150001) 摘要:该…

Windows Server 2003 DNS服务安装篇

导读-- DNS(Domain Name System&#xff0c;域名系统)是一种组织成层次结构的分布式数据库&#xff0c;里面包含有从DNS域名到各种数据类型(如IP地址)的映射“贵有恒&#xff0c;何必三更起五更勤;最无益&#xff0c;只怕一日曝十日寒。”前一段时间巴哥因为一些生活琐事而中止…

正则表达式matlab,正则表达式中一个word的匹配 @MATLAB - 优秀的Free OS(Linux)版 - 北大未名BBS...

我目前想做的就是判断一个str是否可以被认为是有效的MATLAB index。最好的方法是直接运行&#xff0c;然后看运行结果或报错类型&#xff0c;但是我不打算在不知道是什么类型的东西之前运行它&#xff0c;所以可以预先parse一下&#xff0c;简单判断是否“长得跟有效的MATLAB i…

arima模型怎么拟合_7个统计测试,用于验证和帮助拟合ARIMA模型

arima模型怎么拟合什么是ARIMA&#xff1f; (What is ARIMA?) ARIMA models are one of the most classic and most widely used statistical forecasting techniques when dealing with univariate time series. It basically uses the lag values and lagged forecast error…

jQuery禁止Ajax请求缓存

一 现象 get请求在有些浏览器中会缓存。浏览器不会发送请求&#xff0c;而是使用上次请求获取到的结果。 post请求不会缓存。每次都会发送请求。 二 解决 jQuery提供了禁止Ajax请求缓存的方法&#xff1a; $.ajax({type: "get",url: "http://www.baidu.com?_&…

python 实例

参考 http://developer.51cto.com/art/201804/570408.htm 转载于:https://www.cnblogs.com/artesian0526/p/9552510.html