Last Updated: February 25, 2016
·
623
· yitsushi

Start quick dev server with docker

Sometimes I need to start a web-server within current directory. I use Docker and I have a special docker image for it. I just put this snippet into my .zshrc:

startDev() {
  if [[ -n $1 ]]
  then
    NUM=$1
  else
    NUM=1
  fi
  echo ' >>> to get the port from host: dockerport dev-static-'$NUM' 80'
  docker run \
         --rm -t -i -p 80 \
         --name dev-static-$NUM \
         -v `pwd`:/var/www \
         yitsushi/nginx-static-and-php \
        start
}

Now when I want a web-server then I only need to type startDev or if I have multiple instances at the same time startDev 3 or startDev 8. It uses my yitsushi/nginx-static-and-php docker image from docker hub. It has an Nginx, PHP-FPM and GD (maybe it will expanded more PHP lib).

(clockwork) Ξ ~ → cd Development/Experiment
(clockwork) Ξ Development/Experiment → startDev
 >>> Start with "start" in container
 >>> to get the port from host: dockerport dev-static-1 80
>>> Container ID: f89d0ff09040
 * Restarting PHP5 FastCGI Process Manager php5-fpm            [ OK ]

In another terminal I get the port with dockerport becuase I'm on mac and I need this hack because of boot2docker:

(clockwork) Ξ ~ → dockerport dev-static-1 80
192.168.59.103:49171

or just simply:

→ open http://`dockerport dev-static-1 80`

I have an alias for that too :)