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.
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 e.g.
project.dev. Do I need to edit an entry in
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.
One Solution collect form web for “Using Docker Nginx, PHP, MySQL on Mac”
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
MySQL using docker you should
- Container which run Nginx + PHP-FPM (I recommend this image https://hub.docker.com/r/richarvey/nginx-php-fpm/)
- Container run MySQL (https://hub.docker.com/_/mysql/)
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
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
-v /root/docker/mysql56/data/mysql:/var/lib/mysqlit mean I have
/root/docker/mysql56/data/mysqlon my mac, and map it to
mysql56container. So all mysql data will be backup on my local data, and will not lose when I remove the container.
-v $(pwd):/var/www/htmlmean your current directory will be mapped to
container. So, whatever you write in this directory will be exist on
- I use port
8888to avoid conflict with existing web server, you can
change it as you want