Search code examples
nginxdockervagrantparallels

Vagrant Docker Nginx Resolving slow


I got a small issue and hope someone can enlighten me how I can fix this issue with my Development Environment.

I am using MacOS which is, wenn using docker with shared folders, poor in performance.

I originally used an intermediate docker container with unison synchronisation but had issues with it. (Sync stopped unpredictable without any error output or so on)

I created an virtual machine in which I boot up docker. In it I only have a minimal setup with a small php and nginx configuration. (for executing code generation from within the host development IDE). Nginx is configured to forward https to http requests from within the docker containers. (and to get rid of the 80xx ports.

Vagrant doesn't forward any ports and is accessible via the nginx server only from port 80 and 443.

Within docker I have one self compiled nginx container (with several plugins for additional functions like serving compressed files (which lie next to the uncompressed content)etc.), several php7.1-fpm instances, queue worker, mysql master slave database etc. The Environment is built like our productive system. It's important for us to be as close as possible.

The only core difference is the first nginx that sits in between my host and the vm for routing etc.

My Core issue is currently that a request to the first nginx server is extremly slow and I don't really have a clue why. In the Browser Inspector I can see 6 States of the Connection:

  1. Queued (0s)
  2. Stale (5-15s)
  3. Resolving Domain (5-30s)
  4. Request Sent (0.000077s)
  5. Waiting for Response (0.2s)
  6. Downloading Response (0.0009s)

My biggest problem currently on working is step 2 and 3 which only appear within the first connection and every ongoing connection which is delayed longer then 1 minute after the last request.

What I also don't get is why it tries to resolve the domains.

But first things first. Heres an part of my vagrant setup (only the important Parts:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
...
    #Network, Port Mapping, Hostname
    config.vm.network                   "forwarded_port", guest: 3306, host: 3306
    config.vm.network                   "forwarded_port", guest: 6379, host: 6379
    config.vm.network                   "private_network", ip: "192.168.56.142"
    config.hostsupdater.aliases         = ["app.dev", "errbit.dev", "redis.dev", "mailcatcher.dev", "pma.dev", "statsd.dev"]
    config.vm.hostname                  =   "docker.test"
...
end

I am using hostmanager to manage hostfile as I have another dev environment which uses matching domain names but for another service (pma...). I found hostmanager useful as it removes the entries from the hostfile on vagrant stop.

Here is my hostfile

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost

192.168.56.142  docker.test  # VAGRANT: d8fa44be6d190c05689a5d1e3c0b4281 (default) / ca8de87a-7a95-4c7d-97df-2a1a4d606dad
192.168.56.142  app.dev  # VAGRANT: d8fa44be6d190c05689a5d1e3c0b4281 (default) / ca8de87a-7a95-4c7d-97df-2a1a4d606dad
192.168.56.142  errbit.dev  # VAGRANT: d8fa44be6d190c05689a5d1e3c0b4281 (default) / ca8de87a-7a95-4c7d-97df-2a1a4d606dad
192.168.56.142  redis.dev  # VAGRANT: d8fa44be6d190c05689a5d1e3c0b4281 (default) / ca8de87a-7a95-4c7d-97df-2a1a4d606dad
192.168.56.142  mailcatcher.dev  # VAGRANT: d8fa44be6d190c05689a5d1e3c0b4281 (default) / ca8de87a-7a95-4c7d-97df-2a1a4d606dad
192.168.56.142  pma.dev  # VAGRANT: d8fa44be6d190c05689a5d1e3c0b4281 (default) / ca8de87a-7a95-4c7d-97df-2a1a4d606dad
192.168.56.142  statsd.dev  # VAGRANT: d8fa44be6d190c05689a5d1e3c0b4281 (default) / ca8de87a-7a95-4c7d-97df-2a1a4d606dad
10.211.55.26    docker.test.shared docker.test #prl_hostonly shared

VM Docker nginx hostfile:

server {
    listen 443 ssl;
    server_name                 pma.dev;

    ssl_certificate             /vagrant/etc/ssl/server.crt;
    ssl_certificate_key         /vagrant/etc/ssl/server.key;
    ssl_protocols               TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers                 ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS;
    ssl_prefer_server_ciphers   on;

    location / {
        proxy_pass http://localhost:8090;
        proxy_set_header Host $host;
    }
}

I take any advise into consideration for help in any direction. I also already tried several approches but wasn't able to solve it so far. I hope someone can give me a clue what I need to configure different. If you need more Information don't hesitate to ask.


Solution

  • After checking the network traffic with Wireshark I found the issue. I executed an dig on app.dev I recognised that the ip 127.0.53.53 is detected. After also looking into Wireshark I recognised that every access to the .dev domain is queried onto the public dns servers instead of the local hosts file.

    It seems that with macOS every queries ever .dev domain instead of checking the hosts file. Due to this Requests take extra ordinary long. I switch all domains to .test