Local Webapp Development with Docker

Jun 14, 2019

I felt like making a simple template repo for my local webapp development environment. The challenges I wanted to address were:

  • environment/dependency isolation
  • quick prototyping
  • quick push/pull with staging & production environments

Docker helped me solve the environment/dependency injection isolation. Mounting a volume for the Docker setup will help me prototype quickly. Being WordPress oriented, I included a Movefile for wordmove, but wordmove is rsync-based and solves environment push/pull. It only helps that wordmove uses dotenv, so docker-compose and wordmove can utilize the same .env file, making it convenient for a bunch of reasons.

It’s important to note that this repo is MEANT FOR LOCAL DEVELOPEMT ONLY. The Docker configuration exposes the database port on the host which is unecessary in production - the use case for local development is either for pushing/pulling the database with Movefile or manual inspection.

Any php-based webapp can reside under webroot. WordPress is just implied because of the Movefile. The nginx configuration uses the official hack for environment variable injection, but there are cavaets as explained in this SO answer.

One challenge is that the php-fpm image caches requests. Instead of modifying the :latest Docker image, I’d rather just send a docker restart container_id as needed. That way, I can keep this local environment up to date without manual upgrades.

Permissions with Docker Volumes

Permissions probably need to be set correctly on the volumes in order for file read/write/execute either through your editor or the docker container. Since Docker runs under a different user than then one you are writing code with, we need to give proper access. I use Linux & Mac, so welcome the world of ACLs. Following advice from J-C Berthon, I chmod & chown for the Docker user daemon:daemon and set ACLs for my user so I can write code. NOTE: we are using ${whoami} for the group

# set regular file permission ownership to the Docker daemon
sudo chown -R daemon:daemon webroot

# set ACL permissions for your user
sudo find webroot -type d -exec chmod 755 {} \; -exec setfacl -m u:${whoami}:rwx {} \; -exec setfacl -m g:${whoami}:rx {} \; -exec setfacl -m o:rx {} \;
sudo find webroot -type f -exec chmod 644 {} \; -exec setfacl -m u:${whoami}:rw {} \; -exec setfacl -m g:${whoami}:r {} \; -exec setfacl -m o:r {} \;

# make sure the ACL was set
getfacl webroot

Get in touch