Symfony2 app slow response on MacOS & Boot2Docker

I have a slightly big Symfony app, which I was running on Docker by adding all of the files in the Dockerfile, and run everything from within the container. I was doing this only for testing purposes, but now I wanted to switch the dev environment to Docker as well, and tried using -v parameter to mount my local directory into the container using a command like this:

docker run -v /Users/username/pathtofiles:/pathtofilesincontainer -i -p 80:80 -t tag sh /pathtofilesincontainer/init.sh

  • How to mount volume in docker compose version '2' format
  • docker: unauthorized: authentication required
  • Requests hanging on ports forwarded from docker container inside vagrant
  • psql: could not translate host name “somePostgres” to address: Name or service not known
  • docker-compose/boot2docker use in Ubuntu
  • How to config the marathon-lb when the container run in HOST network?
  • This mounts the /Users/username/pathtofiles folder to /pathtofilesincontainer, and runs the init.sh successfully. init.sh is a basic shell script which doesn’t have any impact on performance or anything.

    My ~/.profile file is set correctly and /etc/hosts file has a directive to point current.local to DOCKER_HOST ip.

    When I run the app by copying all of the files into the container via the ADD command in Dockerfile, it runs perfect ~0.5 to 1 sec response time. When I use the above command to mount the same files, it is extremely slow. Page is rendered around 25-35 seconds.

    I’ve searched other topics under SO, but none of them really helped me. I tried disabling xdebug, setting php_ini realcache settings to suggested values, running app/console cahce:clear command, trying to connect to a local mysql server, etc… Nothing worked.

    Anyone have any other ideas, or any suggestions? Thanks in advance!

    My stack is: Symfony2, MySQL, Apache2, Docker 1.3.0, boot2docker 1.3.0, VirtualBox

  • DOCKER installation ERROR “Internal error: Failed to expand shell folder constant ”userdocs" on Windows
  • How to create a new docker image from a running container on Amazon?
  • dockerize does not delay the container initialization
  • Create images from same Dockerfile
  • where does docker attach volume on host machine when its not specified?
  • Vagrant with Docker provider does not share folders
  • 2 Solutions collect form web for “Symfony2 app slow response on MacOS & Boot2Docker”

    I’ve heard of this sort of problem before, and the blame is usually put on the interactions between VirtualBox and the Symfony dev environment. In dev, the cache is rechecked every request, so that any changes are quickly used. Virtualbox isn’t so fast when it comes to the filesystem though, and the number of files checked and updated, well, it’s just too much to be quick as well.

    One trick that may well be worth trying, is to set the cache and logs directory to a path outside the shared folders – under /tmp/, or into a ram-disk, but putting the following into the app/AppKernel.php file.

    public function getCacheDir()
    {
        if (in_array($this->environment, array('dev'))) {
            return '/dev/shm/symfonyprojectname/cache/' . $this->environment;
        }
        return parent::getCacheDir();
    }
    
    public function getLogDir()
    { 
        if (in_array($this->environment, array('dev'))) {
            return '/dev/shm/symfonyprojectname/logs';
        }
        return parent::getLogDir();
    }
    

    You can use Parallel if you have one instead of using VirtualBox to boot boot2docker machine.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.