Docker for Mac is very very slow

Hi all

Docker for mac is currently very slow when I run my environment.
I’m using it for a PHP project using Symfony2 framework.

To render the main PHP request, it lasts 9500ms on Docker Mac.
Using the same configuration ( docker compose file + docker files) on Linux, on the same project, on the same page, the main PHP request lasts 700ms.

I 've tried the same project on different Mac using same/last Docker Beta version and I’ve the same performances.

Do you have any idea where I could start to improve ?

I would be happy to share the informations you need !

Here is my diagnostic ID : 19CEFA36-E990-44D9-8BD7-7498804461BB

Docker for Mac: version: mac-v1.12.0-beta20
OS X: version 10.11.5 (build: 15F34)
logs: /tmp/20160720-224722.tar.gz
[OK] docker-cli
[OK] app
[OK] moby-syslog
[OK] virtualization
[OK] menubar
[OK] system
[OK] osxfs
[OK] db
[OK] slirp
[OK] moby-console
[OK] logs
[OK] vmnetd
[OK] env
[OK] moby
[OK] driver.amd64-linux

Thanks a lot !

Where are your PHP files located?

I’ve noticed that if the files are shared on the Mac, I/O is very slow. My PHP container does a chown -R nginx:nginx /www on startup where the /www directory is shared with the ~/www on the Mac using docker run -v ~/www:/www. The ~/www directory on the Mac has around 8,000 files in it and the chown command takes around 30 seconds to execute.

If I just use a Docker volume (which is in the Moby VM), I/O is back to being fast:

$ docker volume create --name www
$ # init www volume from Mac directory
$ docker run --rm -v www:/www.vm -v ~/www:/www.mac ubuntu:16.04 bash -c "cd /www.mac; tar -cz * | (cd /www.vm; tar -xz)"
$ # run PHP with volume in VM, not on Mac
$ docker run -d-v www:/www ...
1 Like

Hi !

Thanks for your answer.
We are using Docker here for development purpose.
Here is my docker-compose file :slight_smile:

db:
    image: mysql:5.7
    container_name: db
    ports:
      - "3306:3306"
    volumes:
      - "./docker/mysql/custom.cnf:/etc/mysql/conf.d/custom.cnf:ro"
    environment:
      - "MYSQL_ROOT_PASSWORD=root"
      - "MYSQL_USER=project"
      - "MYSQL_PASSWORD=project"
      - "MYSQL_DATABASE=project"
engine:
    build: ./docker/engine/
    container_name: engine
    volumes:
        - ".:/home/docker:rw"
        - "./docker/engine/php.ini:/usr/local/etc/php/conf.d/zzz-custom.ini:ro"
        - "./docker/engine/zzz-custom.conf:/usr/local/etc/php-fpm.d/zzz-custom.conf:ro"
    links:
        - "db:db"
        - "search:search"
    working_dir: "/home/docker"
server:
    image: nginx
    container_name: server
    ports:
        - "80:80"
    links:
        - "engine:engine"
    volumes:
        - ".:/home/docker:ro"
        - "./docker/server/azzaro.dev.conf:/etc/nginx/conf.d/azzaro.dev.conf:ro"

search:
    image: elasticsearch:1.7
    container_name: search
    ports :
        - "9200:9200"

I’m going to try your solution !

@ktwalrus ,How can I translate it into my docker-compose file ?

Thanks for your help.

@ghislefou , I don’t know about the docker-compose file. But, another question – how much RAM does your service need?

Docker for Mac, by default, only allocates a couple GB of RAM for all running containers. I run some memory-intensive tasks in containers and found that they were very slow because they were running out of RAM and swapping. I went into Docker’s Preferences and increased the amount of RAM allocated to containers and things went much faster.

My suggestion is to use a docker volume for your app/cache or var/cache instead of mounting via the filesystem.

When Symfony is in dev mode, it rebuilds it’s cache for every request; which has a tradeoff of being very i/o intensive.

Hi all,

Thanks for your answers, my problem is more global I think, as exposed there : File access in mounted volumes extremely slow, CPU bound

After testing on Windows and Linux, I’ve just noticed these issues only on Mac, with Docker for Mac. My project runs nicely on other OS.

I would probably agree with that. But I think it’s important to note that Symfony has the same types of problems on virtual machines like Virtualbox and VMWare Fusion.

Again, I think if you don’t mount the cache and log folders, it should work just fine.

Sure, but I would consider this latency as acceptable.
9 seconds to render a page is juste too much.

Using virtualbox, vagrant, etc provide much better render time.
Using Docker for Windows or Linux gives 10x faster render time at the moment, mounting cache folder or not.

For me, not mounting the cache folder can be considered as a workaround to hide the current issue.

I just want to confirm this tip. I built a Maven project and thought it would be a good idea to share my cache dir at ~/.m2/repository. Running mvn test-compile using this host mount was 4 to 10 times slower than running the same natively on MacOSX. When using a named volume inside the Moby machine for caching, running the process in the container is only 10% slower than natively. Great tip, thanks!

1 Like

How to do that? Is it possible from docker-compose.yml only?

Yes.

See https://docs.docker.com/compose/compose-file/#/volumes-volume-driver

1 Like

Thanks @mathewpeterson for your answer … For sure, it come from this point because prod mode works much more better
If I take my example, how can I achieve it ?

Currently, I mount the full project path ( “.:/home/docker:rw”).
If I understand your explanation, I have to mount a specific volume for cache and logs folder.
This means that I can’t more anymore all my current folder like that ?

Thanks for your explanation.

@mathewpeterson , here is my dockercompose file, it has no impact, can you tell me what is wrong ? My “engine” container is a based on a php-fpm image.

Thanks !

   db:
    image: mysql:5.7
    container_name: db
    ports:
      - "3306:3306"
    volumes:
        - "./docker/mysql/custom.cnf:/etc/mysql/conf.d/custom.cnf:ro"
        - "./docker/mysql/lib/mysql:/var/lib/mysql:rw"
    environment:
        - "MYSQL_ROOT_PASSWORD=root"
        - "MYSQL_USER=project"
        - "MYSQL_PASSWORD=project"
        - "MYSQL_DATABASE=project"
engine:
    build: ./docker/engine/
    container_name: engine
    volumes:
        - ".:/home/docker:ro"
        - cachevolume:/home/docker/app/cache:rw
        - logvolume:/home/docker/app/logs:rw
        - "./docker/engine/php.ini:/usr/local/etc/php/conf.d/zzz-custom.ini:ro"
        - "./docker/engine/zzz-custom.conf:/usr/local/etc/php-fpm.d/zzz-custom.conf:ro"
    links:
        - "db:db"
        - "search:search"
    working_dir: "/home/docker"
server:
    image: nginx
    container_name: server
    ports:
        - "80:80"
    links:
        - "engine:engine"
    volumes:
        - ".:/home/docker:ro"
        - "./docker/server/decleor-dev.fr.conf:/etc/nginx/conf.d/decleor-dev.fr.conf:ro"
        - "./docker/server/logs/nginx/:/var/log/nginx"

search:
    image: elasticsearch:1.7
    container_name: search
    ports :
        - "9200:9200"