title: Connection refused when making curl request inside docker
body: <p>I have a nginx webserver with docker compose with the following web apps:</p>
  
  <pre><code>example.com
  api.example.com
  </code></pre>
  
  <p>I can curl both sides from outside, but I need to curl from one web page to the other one.</p>
  
  <pre><code>curl example.com -&gt; host not found
  curl nginx -&gt; returns exmaple.com app
  </code></pre>
  
  <p>I tried to set the servername to api.nginx and curling this, but then it says <code>host not found</code></p>
  
  <p>So how do I have to set the configuration so both apps can communicate?</p>
  
  <p>docker-compose:</p>
  
  <pre><code>version: '2'
  
  services:
  
  ### Applications Code Container #############################
  
      applications:
        image: tianon/true
        volumes:
          - ${APPLICATION}:/var/www
  
  ### Workspace Utilities Container ###########################
  
      workspace:
        build:
          context: ./workspace
          args:
            - INSTALL_XDEBUG=${WORKSPACE_INSTALL_XDEBUG}
            - INSTALL_SOAP=${WORKSPACE_INSTALL_SOAP}
            - INSTALL_MSSQL=${WORKSPACE_INSTALL_MSSQL}
            - INSTALL_NODE=${WORKSPACE_INSTALL_NODE}
            - INSTALL_YARN=${WORKSPACE_INSTALL_YARN}
            - INSTALL_DRUSH=${WORKSPACE_INSTALL_DRUSH}
            - INSTALL_AEROSPIKE=${WORKSPACE_INSTALL_AEROSPIKE}
            - INSTALL_V8JS=${WORKSPACE_INSTALL_V8JS}
            - COMPOSER_GLOBAL_INSTALL=${WORKSPACE_COMPOSER_GLOBAL_INSTALL}
            - INSTALL_WORKSPACE_SSH=${WORKSPACE_INSTALL_WORKSPACE_SSH}
            - INSTALL_LARAVEL_ENVOY=${WORKSPACE_INSTALL_LARAVEL_ENVOY}
            - INSTALL_DEPLOYER=${WORKSPACE_INSTALL_DEPLOYER}
            - INSTALL_LINUXBREW=${WORKSPACE_INSTALL_LINUXBREW}
            - INSTALL_MC=${WORKSPACE_INSTALL_MC}
            - PUID=${WORKSPACE_PUID}
            - PGID=${WORKSPACE_PGID}
            - NODE_VERSION=${WORKSPACE_NODE_VERSION}
            - YARN_VERSION=${WORKSPACE_YARN_VERSION}
            - TZ=${WORKSPACE_TIMEZONE}
          dockerfile: "Dockerfile-${PHP_VERSION}"
        volumes_from:
          - applications
        extra_hosts:
          - "dockerhost:${DOCKER_HOST_IP}"
        ports:
          - "${WORKSPACE_SSH_PORT}:22"
        tty: true
        networks:
          - frontend
          - backend
  
  ### PHP-FPM Container #######################################
  
      php-fpm:
        build:
          context: ./php-fpm
          args:
            - INSTALL_XDEBUG=${PHP_FPM_INSTALL_XDEBUG}
            - INSTALL_SOAP=${PHP_FPM_INSTALL_SOAP}
            - INSTALL_MONGO=${PHP_FPM_INSTALL_MONGO}
            - INSTALL_MSSQL=${PHP_FPM_INSTALL_MSSQL}
            - INSTALL_ZIP_ARCHIVE=${PHP_FPM_INSTALL_ZIP_ARCHIVE}
            - INSTALL_BCMATH=${PHP_FPM_INSTALL_BCMATH}
            - INSTALL_PHPREDIS=${PHP_FPM_INSTALL_PHPREDIS}
            - INSTALL_MEMCACHED=${PHP_FPM_INSTALL_MEMCACHED}
            - INSTALL_OPCACHE=${PHP_FPM_INSTALL_OPCACHE}
            - INSTALL_EXIF=${PHP_FPM_INSTALL_EXIF}
            - INSTALL_AEROSPIKE=${PHP_FPM_INSTALL_AEROSPIKE}
            - INSTALL_MYSQLI=${PHP_FPM_INSTALL_MYSQLI}
            - INSTALL_TOKENIZER=${PHP_FPM_INSTALL_TOKENIZER}
            - INSTALL_INTL=${PHP_FPM_INSTALL_INTL}
            - INSTALL_GHOSTSCRIPT=${PHP_FPM_INSTALL_GHOSTSCRIPT}
            - INSTALL_LDAP=${PHP_FPM_INSTALL_LDAP}
            - INSTALL_SWOOLE=${PHP_FPM_INSTALL_SWOOLE}
          dockerfile: "Dockerfile-${PHP_VERSION}"
        volumes_from:
          - applications
        volumes:
          - ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini
        expose:
          - "9000"
        depends_on:
          - workspace
        extra_hosts:
          - "dockerhost:${DOCKER_HOST_IP}"
        environment:
          - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
        networks:
          - backend
  
  ### PHP Worker Container #####################################
  
      php-worker:
        build:
          context: ./php-worker
        volumes_from:
          - applications
        depends_on:
          - workspace
        extra_hosts:
          - "dockerhost:${DOCKER_HOST_IP}"
        networks:
          - backend
  
  ### MySQL Container #########################################
  
      mysql:
        build:
          context: ./mysql
        environment:
          - MYSQL_DATABASE=${MYSQL_DATABASE}
          - MYSQL_USER=${MYSQL_USER}
          - MYSQL_PASSWORD=${MYSQL_PASSWORD}
          - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
        volumes:
          - ${DATA_SAVE_PATH}/mysql:/var/lib/mysql
          - ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
        ports:
          - "${MYSQL_PORT}:3306"
        networks:
          - backend
          - frontend
  
  ### Redis Container #########################################
  
      redis:
        build: ./redis
        volumes:
          - ${DATA_SAVE_PATH}/redis:/data
        ports:
          - "6379:6379"
        networks:
          - backend
  
  ### Caddy Server Container ##################################
  
      caddy:
        build: ./caddy
        volumes_from:
          - applications
        volumes:
          - ${CADDY_CUSTOM_CADDYFILE}:/etc/Caddyfile
          - ${CADDY_HOST_LOG_PATH}:/var/log/caddy
          - ${DATA_SAVE_PATH}:/root/.caddy
        ports:
          - "${CADDY_HOST_HTTP_PORT}:80"
          - "${CADDY_HOST_HTTPS_PORT}:443"
        depends_on:
          - php-fpm
        networks:
          - frontend
          - backend
  
  ### Adminer Container ####################################
  
      adminer:
        build:
          context: ./adminer
          args:
            - INSTALL_MSSQL=${ADM_INSTALL_MSSQL}
        ports:
          - "${ADM_PORT}:8080"
        depends_on:
          - php-fpm
        networks:
          - frontend
          - backend
  
  ### Laravel Echo Server #######################################
      laravel-echo-server:
        build:
          context: ./laravel-echo-server
        volumes:
          - ./laravel-echo-server/laravel-echo-server.json:/app/laravel-echo-server.json:ro
        ports:
          - "${LARAVEL_ECHO_SERVER_PORT}:6001"
        links:
          - redis
        networks:
          - frontend
          - backend
  
  ### Networks Setup ############################################
  
  networks:
    frontend:
      driver: "bridge"
    backend:
      driver: "bridge"
  
  ### Volumes Setup #############################################
  
  volumes:
    mysql:
      driver: "local"
    percona:
      driver: "local"
    mssql:
      driver: "local"
    postgres:
      driver: "local"
    memcached:
      driver: "local"
    redis:
      driver: "local"
    neo4j:
      driver: "local"
    mariadb:
      driver: "local"
    mongo:
      driver: "local"
    minio:
      driver: "local"
    rethinkdb:
      driver: "local"
    phpmyadmin:
      driver: "local"
    adminer:
      driver: "local"
    aerospike:
      driver: "local"
    caddy:
      driver: "local"
    elasticsearch-data:
      driver: "local"
    elasticsearch-plugins:
      driver: "local"
  </code></pre>