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.
Do I need to install php-fpm and mySQL within my container since my container is only NGINX at this stage?
How do I configure my project on a custom domain eg 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?
Lastly do I need a dockerfile
? I already have my container up and my understanding is a dockerfile is only for defining your container?
An example of a dockerfile for NGINX, PHP and mySQL would be helpful to look at as well.
Thanks
No, this guide just show using nginx container in docker. But I see the container don't have php installed. And you cannot install php-fpm
inside this container.
So, if you want to use nginx
, php
, and MySQL
using docker you should pull
:
Download images
docker pull richarvey/nginx-php-fpm
docker pull mysql:5.6
Run MySQL Instance. Name it mysql56, and expose using port 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. Link it to MySQL Instance, and name it 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.
To make nginx can be accessed with address project.dev
, just map it on /etc/hosts
. Then access it on web browser 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. So all mysql data will be backup on my local data, and will not lose when I remove the container. -v $(pwd):/var/www/html
mean your current directory will be mapped to container. So, whatever you write in this directory will be exist on /var/www/html
container. 8888
to avoid conflict with existing web server, you can change it as you want
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.