Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker mac symfony 3 very slow

I'm starting a new project with Symfony 3 and I want to use Docker for the development environment. We will work on this project with a dozen developers so I want to have an easy install process.

Here's my docker-compose.yml

version: '2'
services:
db:
    image: mysql
    ports:
        - "3307:3306"
    environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: mydb
        MYSQL_USER: root
        MYSQL_PASSWORD: root
php:
    build: ./php-fpm
    expose:
        - "9001"
    volumes:
        - .:/var/www/project
        - ./var/logs:/var/www/project/app/logs
    links:
        - db
nginx:
    build: ./nginx
    ports:
        - "8001:80"
    links:
        - php
    volumes_from:
        - php
    volumes:
        -  ./var/logs/nginx/:/var/log/nginx

I installed the recent Docker for Mac application (beta). The big issue is that my symfony app is very very slow (a simple page takes more than 5 seconds). The same app with MAMP is much faster (500ms max). Is this a know issue of Docker ? How can I debug it ?

like image 686
J. Doe Avatar asked Jul 02 '16 18:07

J. Doe


4 Answers

This is a known issue. Your local file system is being mounted in the Docker for Mac linux VM with osxfs, there is some additional latency when reading and writing these mounted files. For small applications this isn't too noticeable, but for larger applications that could read thousands of files on a single request it is can slow things down significantly.

like image 52
Andrew Kett Avatar answered Sep 21 '22 09:09

Andrew Kett


Sorry for the late answer but you could install Docker CE Edge, because it supports cache mode.

  • Download Docker-Edge (waiting for the stable version of docker that will support cached mode)
  • Add the following line to your docker-compose.yml file

Blockquote

php:
    volumes:
        - ${SYMFONY_APP_PATH}:/var/www/symfony:cached

Replace ${SYMFONY_APP_PATH} by your own path.

like image 34
Fr4NgUs Avatar answered Sep 20 '22 09:09

Fr4NgUs


Actually I'm using docker to run projects locally. To run Docker faster the I used the below setup:

MAC OSX:

Docker Toolbox

Install normaly the dmg file.

Open your terminal and type:

`$ docker-machine create --driver virtualbox default `

`$ docker-machine env default`

`eval "$(docker-machine env default)"`

Now you have the docker-machine up and running, any docker-compose, docker command will run "inside the machine".

In our case "Symfony" is a large application. The docker-machine file system is under osxfs, so the application will be very slow.

docker-machine-nfs

Install with:

curl -s https://raw.githubusercontent.com/adlogix/docker-machine-nfs/master/docker-machine-nfs.sh | sudo tee /usr/local/bin/docker-machine-nfs > /dev/null && \ sudo chmod +x /usr/local/bin/docker-machine-nfs

Running

It will be necessary to type the root password

$ docker-machine-nfs default

Now your docker-machine is running under the nfs file system.

The speed will be regular.

Mapping your docker-machine to localhost

Regulary the docker container will run under 192.168.99.100:9000

Running on terminal:

$ vboxmanage modifyvm default --natpf1 "default-map,tcp,,9000,,9000'

You can access from localhost:9000

like image 32
Roger Cruz Avatar answered Sep 19 '22 09:09

Roger Cruz


It's possible to get performance with Docker for Mac almost as fast as native shared volumes with Linux by using Mutagen. A benchmark is available here.

I created a full example for a Symfony project, it can be used for any type of project in any language.

like image 22
Kwadz Avatar answered Sep 19 '22 09:09

Kwadz