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 and have NGINX running fine and can see the NGINX landing page.

  • Installing libraries in ubuntu image using Docker
  • Extend Existing Docker Image
  • Running docker container at specific URL(s)
  • How to use env var in WORKDIR stanza?
  • How to install docker daemon when resizing data center cluster size in Mesosphere?
  • Docker for Windows 10 //./pipe/docker_engine: access is denied
  • 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. Do I need to edit an entry in /etc/hosts for 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.


  • Scope of the 'read-only' flag when mounting a volume in Docker
  • Copy Postgres database structures but not data
  • Some exposed Docker ports are not accessible from outside (dovecot, postfix)
  • How to ignore certificate errors in Boot2Docker on windows
  • Can Docker containers (NOT Docker images) be moved?
  • JBoss Fuse, creating container with ActiveMQ
  • 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 nginx, php, and MySQL using docker you should pull:

    1. Container which run Nginx + PHP-FPM (I recommend this image
    2. Container run MySQL (

    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, just map it on /etc/hosts. Then access it on web browser


    • -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.
    • I use port 8888 to avoid conflict with existing web server, you can
      change it as you want
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.