Docker mac symfony 3 very slow

爷,独闯天下 提交于 2020-06-08 17:20:52

问题


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 ?


回答1:


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.




回答2:


sorry for the late answer but you could install docker ce edge caused 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.




回答3:


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




回答4:


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




回答5:


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.




回答6:


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




回答7:


It's possible to get performance on 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.



来源:https://stackoverflow.com/questions/38163447/docker-mac-symfony-3-very-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!