8

My problem is the following - I have Docker on OSX with containers containing Redis, NginX, PHP 7 and Unison. Mapped to php-container I have volume with Symfony 3.1.7.

Everything works, but Symfony's "Welcome" page taked ~1.5 second loading time on average. At the same time same setup without docker gives me 0.2 second loading time. Same difference I got for Symfony's console commands, so, I guess, it's not the problem with NginX, and Unison should've negated all issues related to Docker files sync on OSX problem.

Right now I've ran out of ideas what can I do to speed things up and how to figure out what creates that 1.5s delay.

I have same issue on my second MBP, but such thing does not happen on colleagues laptop, which is similar to the one I have, but we were unable to find any difference between two setups.

Everything is running on my MBP with 2.5 GHz i5, 8 Gb RAM and SSD.

Docker 1.12.3, OSX 10.12.1 (Sierra)

docker-compose.yml:

mydockerbox-redis:
  image: phpdockerio/redis:latest
  container_name: mydockerbox-redis

mydockerbox-webserver:
  image: phpdockerio/nginx:latest
  container_name: mydockerbox-webserver
  volumes:
      - ..:/var/www/mydockerbox
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
  ports:
   - "80:80"
  links:
   - mydockerbox-php-fpm

unison:  
  image: leighmcculloch/unison:latest  
  environment:  
    - UNISON_WORKING_DIR=/unison  
  volumes:
    - ../mydockerbox:/var/www/mydockerbox
  ports:  
    - "5000:5000"

mydockerbox-php-fpm:
  build: .
  dockerfile: php-fpm/Dockerfile
  container_name: mydockerbox-php-fpm
  volumes_from:  
    - unison  
  volumes:
    - ./php-fpm/php-ini-overrides.ini:/etc/php/7.0/fpm/conf.d/99-overrides.ini
  links:
    - mydockerbox-redis

UPD And here is Dockerfile for php-fpm container:

FROM phpdockerio/php7-fpm:latest

# Install selected extensions and other stuff
RUN apt-get update \
    && apt-get -y --no-install-recommends install  php7.0-mongodb php7.0-redis php7.0-igbinary \
    && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*


WORKDIR "/var/www/mydockerbox"
Sergii Nester
  • 477
  • 2
  • 8
  • 14
  • which driver do you use for the docker machine? – Matteo Nov 27 '16 at 19:20
  • @Matteo - I'm pretty new to Docker, so I might be wrong, but as far as I understood - this version of Docker claims to be native for OSX, so I guess - it just Docker, no VirtualBox or Vagrant or some other stuff like that. – Sergii Nester Nov 27 '16 at 19:24
  • 1
    if you launch `docker-machine ls` you can see the column DRIVER – Matteo Nov 27 '16 at 20:13
  • @Matteo `docker-machine ls` displays empty list - I'm just using Docker, without anything else. – Sergii Nester Nov 27 '16 at 21:00
  • Docker is a Linux thing. On Windows or OSX it requires a virtual machine to run a base Linux kernel. Plain Docker on OSX wil be using the Hyperkit VM. Instead switch to Docker Toolbox wwhich uses Virtualbox. Ref. https://docs.docker.com/docker-for-mac/docker-toolbox/ – Ed Randall Jan 07 '18 at 19:18
  • @EdRandall - oh, dude, that was exactly the point of my question - how to make everything work properly without having to use any additional virtualisation software, how to use only native OSX virtualisation instead of using VirtualBox or something else. – Sergii Nester Jan 26 '18 at 10:48
  • @SergeyNester have a look at https://stackoverflow.com/questions/17547112/why-cant-you-install-docker-natively-in-osx – Ed Randall Jan 29 '18 at 08:35
  • @EdRandall well, that was almost 5 years ago, since then a lot has changed, e.g. https://www.docker.com/docker-news-and-press/docker-released-native-mac-and-windows-apps-optimize-developer-experience – Sergii Nester Jan 30 '18 at 09:39
  • The top answer here may explain my 'Docker is a Linux thing' comment more clearly: https://stackoverflow.com/questions/16047306/how-is-docker-different-from-a-virtual-machine - even now [runc](https://github.com/opencontainers/runc) supports only the Linux platform. – Ed Randall Dec 27 '18 at 13:26

2 Answers2

1

I suggest you to use the docker-machine-driver-xhyve:

docker-machine/libmachine driver plugin for xhyve/hyperkit (native macOS hypervisor.framework)

You can simply install with brew (I hope you have already installed docker&Co with brew also, otherwise unlink and install them with brew!):

brew install docker-machine-driver-xhyve
sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve

Then you can create a docker machine as:

docker-machine create --driver xhyve --xhyve-experimental-nfs-share my-xhyve-docker-machine

and use it for run your container

Matteo
  • 37,680
  • 11
  • 100
  • 115
  • Thanks for your suggestion, but right now I'm still hoping to make Docker run properly by itself, without VirtualBox or other additional VM engines. – Sergii Nester Nov 27 '16 at 20:10
  • Hi @SergeyNester the abstraction layer is very slow accessing the file system. I find a good improvement with the use of this driver. – Matteo Nov 28 '16 at 15:08
0

First, benchmark PHP performance inside your php-fpm container (using this for example) and compare it with your colleague's container.

If you find that performance is the same/comparable, then use PHP performance profiling tools to find out what Symfony does in every bit of those ~1.5 seconds while generating "Welcome" page. That will likely identify the bottleneck (could be filesystem, network communication with Redis container, DNS lookups etc).

If the benchmark shows that PHP itself in your container runs slower (which I think is unlikely), then run the benchmark on the host machine. In case there is big difference between the host machine's and the php-fpm contaner's results — that will mean docker engine is throttling resources and needs a deep tweak or reinstall.

Greendrake
  • 3,657
  • 2
  • 18
  • 24
  • Funnily enought, that benchmark takes less time in the container)) Right now I've already removed container with Redis, and there is should be no DNS lookups. Judging by Symfony profiler more than a second is spent for "Symfony initialization". I guess that leaves me with some unknown filesystem problems, that Unison is unable to handle. – Sergii Nester Nov 27 '16 at 21:47
  • About Symfony... @SergeyNester – have you found solution to decrease "Symfony initialization" time? – cadavre Mar 30 '17 at 11:30
  • @cadavre nope, I gave up – Sergii Nester Mar 30 '17 at 12:21