title: Connection to server in Docker container on localhost very slow
body: <p>I wanted to try Docker as a tool for local development — I used <code>docker-compose</code> to spin up 3 containers: one for the database (postgres), front-end (running webpack and node sass in watch mode) and backend (Elixir/Phoenix).</p>
  
  <p>Everything works great, except that when I hit <code>localhost:4000</code> the page load is really slow — 10-15 seconds just to get the login page, which is static.</p>
  
  <p>I checked the logs from <code>docker-compose</code> and the server response times are fast as usual, which to me it means that something is slowing down the connection to the container.</p>
  
  <p>When I ran the server directly in the Terminal again, everything is pretty fast, e.g. takes 1s to load the same page.</p>
  
  <p>I'm new to Docker so I suspect I might be missing something configuration-wise. Any ideas are appreciated. Thank you!</p>
  
  <p><strong>Configuration</strong></p>
  
  <p><em>docker-compose.yml</em></p>
  
  <pre><code>version: "3.6"
  
  services:
    postgres:
      container_name: postgres
      image: postgres:11.0-alpine
      ports:
        - 5432:5432
      volumes:
        - postgres:/var/lib/postgresql/data
  
    front-end:
      container_name: front-end
      env_file:
        - "docker/dev/.env"
      build:
        context: "."
        dockerfile: "docker/dev/Dockerfile.front-end"
      volumes:
        - .:/app
        - node_modules:/app/node_modules
        - static:/app/priv/static
      command: npm run dev
  
    backend:
      container_name: backend
      build:
        context: "."
        dockerfile: "docker/dev/Dockerfile.backend"
      env_file:
        - "docker/dev/.env"
      depends_on:
        - postgres
        - front-end
      ports:
        - 4000:4000
      stdin_open: true
      tty: true
      volumes:
        - .:/app
        - elixir-deps:/app/deps
        - static:/app/priv/static
      command: iex -S mix phx.server
  
  volumes:
    postgres:
    elixir-deps:
    node_modules:
    static:
      driver_opts:
        type: "tmpfs"
        device: "tmpfs"
  </code></pre>
  
  <p><em>Dockerfile.front-end</em></p>
  
  <pre><code>FROM node:8.10-alpine
  
  WORKDIR /app
  
  COPY package.json ./
  COPY package-lock.json ./
  
  RUN npm install
  
  COPY . .
  </code></pre>
  
  <p><em>Dockerfile.backend</em></p>
  
  <pre><code>FROM elixir:1.8-alpine
  
  RUN apk update &amp;&amp; apk add build-base inotify-tools postgresql-dev
  
  WORKDIR /app
  
  COPY mix.exs ./
  COPY mix.lock ./
  
  RUN mix local.hex --force &amp;&amp; mix local.rebar --force \
      &amp;&amp; mix deps.get &amp;&amp; mix deps.compile
  
  COPY . .
  
  EXPOSE 4000
  </code></pre>
  
  <p><strong>Versions &amp; other info:</strong></p>
  
  <pre><code>MacOS Mojave 10.14.3
  Docker Desktop 2.0.0.3 (Engine 18.09.2, Compose: 1.23.2)
  
  MacBook Pro 13" (Early 2015, 16GB RAM/3.1GHz Core i7)
  </code></pre>