简体   繁体   English

在Mac上使用Docker Nginx,PHP,MySQL

[英]Using Docker Nginx, PHP, MySQL on Mac

I'm just starting to get my head around docker and want to use it for a project. 我刚刚开始着手解决码头工作者,并希望将其用于项目。

I have followed https://docs.docker.com/docker-for-mac/#explore-the-application-and-run-examples and have NGINX running fine and can see the NGINX landing page. 我已经关注了https://docs.docker.com/docker-for-mac/#explore-the-application-and-run-examples并且NGINX正常运行并且可以看到NGINX登录页面。

Do I need to install php-fpm and mySQL within my container since my container is only NGINX at this stage? 我需要在我的容器中安装php-fpm和mySQL,因为我的容器在这个阶段只是NGINX吗?

How do I configure my project on a custom domain eg project.dev . 如何在自定义域上配置项目,例如project.dev Do I need to edit an entry in /etc/hosts for 127.0.0.1 project.dev and then listen for that URL in an NGINX config? 我是否需要在/etc/hosts编辑127.0.0.1 project.dev的条目,然后在NGINX配置中侦听该URL?

Lastly do I need a dockerfile ? 最后我需要一个dockerfile吗? I already have my container up and my understanding is a dockerfile is only for defining your container? 我已经有了我的容器,我的理解是dockerfile只用于定义容器?

An example of a dockerfile for NGINX, PHP and mySQL would be helpful to look at as well. NGINX,PHP和mySQL的dockerfile示例也有助于查看。

Thanks 谢谢

No, this guide just show using nginx container in docker. 不,本指南只显示在docker中使用nginx容器。 But I see the container don't have php installed. 但我看到容器没有安装php。 And you cannot install php-fpm inside this container. 而你无法在这个容器中安装php-fpm

So, if you want to use nginx , php , and MySQL using docker you should pull : 所以,如果你想使用nginx使用nginxphpMySQL你应该pull

  1. Container which run Nginx + PHP-FPM (I recommend this image https://hub.docker.com/r/richarvey/nginx-php-fpm/ ) 运行Nginx + PHP-FPM的容器(我推荐这个图片https://hub.docker.com/r/richarvey/nginx-php-fpm/
  2. Container run MySQL ( https://hub.docker.com/_/mysql/ ) 容器运行MySQL( https://hub.docker.com/_/mysql/

Download images 下载图片

docker pull richarvey/nginx-php-fpm
docker pull mysql:5.6

Run MySQL Instance. 运行MySQL实例。 Name it mysql56, and expose using port 3360 将其命名为mysql56,并使用端口3360公开

docker run -tid -p 3360:3306 --name mysql56 -e MYSQL_ROOT_PASSWORD=123456 -v /root/docker/mysql56/data/mysql:/var/lib/mysql  -d mysql:5.6

Run Nginx PHP+FPM instance. 运行Nginx PHP + FPM实例。 Link it to MySQL Instance, and name it project-dev 将其链接到MySQL实例,并将其命名为project-dev

docker run -tid --name project-dev --link mysql56:mysql -v $(pwd):/var/www/html -p 8888:80 richarvey/nginx-php-fpm:latest

Run docker ps -a to see the running containers. 运行docker ps -a以查看正在运行的容器。

To make nginx can be accessed with address project.dev , just map it on /etc/hosts . 要使用地址project.dev访问nginx,只需将其映射到/etc/hosts Then access it on web browser http://project.dev:8888 然后在网络浏览器http://project.dev:8888上访问它

Note : 注意

  • -v /root/docker/mysql56/data/mysql:/var/lib/mysql it mean I have /root/docker/mysql56/data/mysql on my mac, and map it to /var/lib/mysql in mysql56 container. -v /root/docker/mysql56/data/mysql:/var/lib/mysql这意味着我的mac上有/root/docker/mysql56/data/mysql ,并将它映射到mysql56容器中的/var/lib/mysql So all mysql data will be backup on my local data, and will not lose when I remove the container. 因此,所有mysql数据都将备份在我的本地数据上,并且在删除容器时不会丢失。
  • -v $(pwd):/var/www/html mean your current directory will be mapped to container. -v $(pwd):/var/www/html表示您当前的目录将映射到容器。 So, whatever you write in this directory will be exist on /var/www/html container. 因此,无论您在此目录中编写什么,都将存在于/var/www/html容器中。
  • I use port 8888 to avoid conflict with existing web server, you can change it as you want 我使用端口8888来避免与现有的Web服务器冲突,您可以根据需要进行更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM