RSS Feed

Symfony development with docker on a mac


I recently started to do all PHP development with docker, since I was just tired of installing tons of dev libraries on my machine. Most of which i couldn’t even remember what they actually were good for.

When I first tried docker (docker-toolbox for mac) I was really disappointed how slow symfony apps ran inside the container.

I did a bit of research (didn’t completely get it though) – but most of the speed issues that people experience seem to be related to the rather slow file system access in mounted folders.

That’s where dlite really shines.
It’s an app that uses some sort of alternative to virtualbox etc. which has significant speed advantages.

I highly recommend you give it a try if you’re developing with docker in OSX.
Installation with homebrew is quite simple:

brew install dlite
dlite stop && dlite update -v 2.3.0 && dlite start
brew install docker
brew install docker-compose

Another thing I found quite challenging was setting up permissions when running symfony inside docker.
I found a couple of tutorials on that but none of those seemed to really work with my setup.

You could use data containers for the cache and log folders and don’t have any permission problems.
Or just use some internal folder `/tmp/myapp/cache` or `/dev/shm/myapp` (the latter really is fast…).

But any of those approaches will make it difficult to access the cache files from the host.
(I use PHPStorm with the symfony plugin, which relies on parsing some cache files)
It also doesn’t solve the problem of persmissions for the `/web` folders, when installing assets or write to any data folders you also wan’t to mount from the host filesystem.

I have not found a really elegant solution for that, but there’s a workaround which does work magic:

You can set uid of the www-data inside the container your host users’ uid.
Something like `RUN usermod -u 501 www-data` inside your webserver Dockerfile should do the trick for your default user on mac. You can then log into the container and run symfony commands as www-data and have no problems with accessing files from host filesystem, command-line or the webserver.

We put together a docker setup for symfony development, which should work across different operating systems.

So as a quickstart, after installing docker & dlite just run:

git clone docker-sf3
cp -r docker-sf3/docker /path/to/your/symfony-project/
cd /path/to/your/symfony-project/docker
sh ./ -l

3 responses to “symfony development with docker on a mac”

Leave a Reply

Your email address will not be published. Required fields are marked *