Docker Community Forums

Share and learn in the Docker community.

Docker is slower than Vagrant several times?

(Onkeltem) #1

We’ve been experiencing unacceptable performance degradation of our dockerized application when we run them on Mac. The application is a Drupal 8 website running inside two regular containers: web (with apache and mod_php) and db (with mariadb).

We mount two things from the host’s filesystem:

– website’s sources
– regular InnoDB database (a named volume).

On three different Mac machines we have our website running 10-20 times slower them natively on Linux. I don’t speak about milliseconds, no - the impact is severe, our frontpage can load for minutes.

I’d been trying to figure our some reasons of this for 3 months but I didn’t find anything. Then we tried to run our website inside a Vagrant machine and it turned to be 5-6 times faster then in docker.

The only difference between docker and vagrant setups is that in the latter case we have our database running inside the machine (while it’s a named volume in docker).

I then compared configurations of the docker and vagrant VMs and at the very least they are the same, more than that:

– 1) docker VM: 2 × CPU + 16GB RAM
– 2) vagrant VM: 1 × CPU + 2GB RAM

So my question is: what is so wrong with docker on Mac that it is several times slower than Vagrant - in fact a thing which is using just another virtual machine??

(Rasmartin) #2

Docker for Mac and mounted volumes are slow in general! You will find a lot of stuff on Google about this topic. This has to do with MacOS itself. I didn’t find a satisfiable solution to speed this up.

I’ve here a development setup of an PHP application (PHP-FPM+Nginx, Database is external). First we tried Docker for Mac. It was horrible slow. It took up to seconds until an edited file was available inside the container and for this accessible by PHP-FPM. So we tried to do a workaround with docker-sync. But this solution was crap. Sync died after a few hours with the result that you need to restart the whole development environment. Now we have a solution with Parallels+vagrant+boot2docker, which works better. The sync-problems have gone away. But file access in the container is still slow.

How I know this? If I mount the source code into the docker container, I need for an AJAX-call, that is processed by PHP, up to 3 seconds. If I run the same application with the source code inside the container (no mounts, like in production), the request is processed in less than 1 sec.
The volume mounts are the problem. I guess you can verify this, if you remove your mounts.

Of course, if the main location of your source-files is inside a VM, without mounts from the hostsystem to the VM, you will have a better performance.

Hope that this is an answer to your question.

(Jhsu802701) #3

On a Mac, you should install a Linux virtual machine with VirtualBox. Use Docker from within this Linux virtual machine. Docker for Linux (even as a guest OS) is faster than Docker for Mac.