J. Doe
J. Doe

Reputation: 61

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 ?

Upvotes: 5

Views: 6952

Answers (7)

Roger Cruz
Roger Cruz

Reputation: 1001

Actually I'm using docker to run projects locally. To run Docker faster 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

Upvotes: 3

Kwadz
Kwadz

Reputation: 2232

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.

Upvotes: 1

Fr4NgUs
Fr4NgUs

Reputation: 476

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.

Upvotes: 6

Arkowsky
Arkowsky

Reputation: 903

Known issue

This is known issue https://forums.docker.com/t/file-access-in-mounted-volumes-extremely-slow-cpu-bound/8076.

I won't recommend https://www.docker.com/products/docker-toolbox if you have https://www.docker.com/docker-mac.

Docker for Mac does not use VirtualBox, but rather HyperKit, a lightweight macOS virtualization solution built on top of Hypervisor.framework in macOS 10.10 Yosemite and higher. https://docs.docker.com/docker-for-mac/docker-toolbox/#the-docker-for-mac-environment

My workaround

I have created workaround which may help you. I use http://docker-sync.io/ for my symfony project. Before using docker-sync page was loading 30 sec, now it's below 1 sec - https://github.com/Arkowsky/docker_symfony

Upvotes: 0

Joseph Astrahan
Joseph Astrahan

Reputation: 9082

I have a detailed solution to this problem in my answer here, docker on OSX slow volumes, please check it out.

I got it where there is no slow downs and no extra software to install.

Upvotes: 0

Kerruba
Kerruba

Reputation: 2019

I had a similar problem. In my case I was running a python script within a docker container and it was really slow. The way I solved this is using the "old" docker-toolbox.

It's not ideal, but worked for me

Upvotes: 0

Andrew Kett
Andrew Kett

Reputation: 193

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.

Upvotes: 6

Related Questions