5

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 ?

J. Doe
  • 61
  • 1
  • 3
  • it's a beta app, you should try their traditional toolbox https://www.docker.com/products/docker-toolbox, if it's the same slow, then I'd start digging deeper... – vitr Jul 02 '16 at 22:06

7 Answers7

6

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.

Andrew Kett
  • 193
  • 1
  • 10
  • Do you know any workarounds for the issue? I'd prefer to keep using the docker for mac so I can use docker-compose files – Joseph Astrahan Mar 08 '17 at 14:49
  • I don't have a work around unfortunately. I am using dinghy for my magento 2 dev until docker for mac performance improves to the point where it's bearable. https://github.com/codekitchen/dinghy – Andrew Kett Mar 08 '17 at 19:35
  • I found a workaround that works perfectly, I posted my answer here, http://stackoverflow.com/questions/38168130/docker-on-osx-slow-volumes/42679301#42679301 – Joseph Astrahan Mar 09 '17 at 16:49
  • Its super fast and it works great the fix, please check it out and let me know what you think. I'll post the answer here as well – Joseph Astrahan Mar 09 '17 at 16:50
6

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.

Ondrej Slinták
  • 31,386
  • 20
  • 94
  • 126
Fr4NgUs
  • 468
  • 6
  • 9
3

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

Roger Cruz
  • 841
  • 6
  • 8
  • You should not be using the VirtualBox solution anymore - [Docker for Mac](https://www.docker.com/docker-mac) is now the recommended development environment for macOS – MTCoster May 30 '17 at 19:43
1

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.

Kwadz
  • 2,206
  • 2
  • 24
  • 45
0

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

Kerruba
  • 1,779
  • 1
  • 17
  • 25
0

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.

Community
  • 1
  • 1
Joseph Astrahan
  • 8,659
  • 12
  • 83
  • 154
0

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

Arkowsky
  • 851
  • 7
  • 19