Installing Laddr using the Emergence Docker Container


#1

I’ll be working on this guide over time… for now don’t mind if it seems I just dropped things in here as I figured them out.

Maybe I did… <__<… >_>…

Initial Setup

  1. I performed these steps using Digital Ocean’s pre-built Docker droplet image. If you use Digital Ocean, the 1GB/1vCPU plan should work.

  2. Run the docker container… ([this comes from here]
    NOTE: If you want to use the Let’s Encrypt container method for SSL, use the docker run command from the “Let’s Encrypt” section below instead) (https://github.com/CodeForPhilly/laddr/blob/develop/docs/laddr/development/clone-from-git.md))

     docker run -d \
     -it \
     --name emergence \
     -v /emergence:/emergence \
     -p 80:80 \
     -p 3306:3306 \
     -p 9083:9083 \
     jarvus/emergence \
     tmux new -s emergence emergence-kernel
    
  3. As root: cd /etc/init.d

  4. Create a new file, laddr and stuff these contents in there:

#! /bin/sh

case "$1" in
      start)
            cd /emergence
            rm kernel.sock
            rm ./services/run/nginx/nginx.pid
            rm ./services/run/mysqld/mysqld.pid
            rm ./services/run/php-fpm/php-fpm.pid
            docker start emergence
            ;;
      stop)
            docker kill emergence
            ;;
esac
exit 0
  1. chmod +x laddr
  2. update-rc.d testjava defaults

If you checked out the laddr file contents, you might have noticed there’s currently an issue where Emergence won’t restart if it detects its relevant .sock and .pid files. This script ensures that if your server is rebooted, Emergence (and your Laddr site(s)) will pop back up!

If you stop the docker container manually you’re going to have to remove those files. Technically you could split the rm commands into a separate script for that. ¯_(ツ)_/¯

After you’re up and running, follow this guide for setting up your staging and production sites!

HTTPS via Let’s Encrypt!

After setting up your staging and production sites with the above instructions, let’s upgrade to HTTPS!

  1. Next you’ll need jwilder/nginx-proxy. This creates an nginx reverse proxy that will pass requests down to our emergence sites. We’ll add an additional container after this that auto-configures SSL for us.
docker run -d -p 80:80 -p 443:443 \
    --name nginx-proxy \
    -v /opt/nginx/certs:/etc/nginx/certs:ro \
    -v /etc/nginx/vhost.d \
    -v /usr/share/nginx/html \
    -v /var/run/docker.sock:/tmp/docker.sock:ro \
    --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy \
--restart always \
    jwilder/nginx-proxy
  1. And this neat additional container that will auto-register certificates for us!
docker run -d \
    -v /opt/nginx/certs:/etc/nginx/certs:rw \
    -v /var/run/docker.sock:/var/run/docker.sock:ro \
    --volumes-from nginx-proxy \
--restart always \
    jrcs/letsencrypt-nginx-proxy-companion
  1. Now let’s make our Emergence container. Tweak VIRTUAL_HOST, LETSENCRYPT_HOST (comma separated list of your site’s domains / subdomains. Remember to do staging and production!) as well as LETSENCRYPT_EMAIL and all the domains/subdomains under the “–add-host” flags.
docker run -d \
    -it \
    -e "VIRTUAL_HOST=mysite.com,www.mysite.com,staging.mysite.com" -e "LETSENCRYPT_HOST=mysite.com,www.mysite.com,staging.mysite.com" -e "LETSENCRYPT_EMAIL=my@email.com" \
    --name emergence \
    -v /emergence:/emergence \
    --expose=80 \
    -p 3306:3306 \
    -p 9083:9083 \
   --add-host mysite.com:127.0.0.1 \
   --add-host www.mysite.com:127.0.0.1 \
   --add-host staging.mysite.com:127.0.0.1 \
    jarvus/emergence \
    tmux new -s emergence emergence-kernel

Docker doesn’t seem to like having environment options broken out onto multiple lines