title: React/Next.js docker build failing when trying to reach out to local API endpoint
body: <p>I cannot seem to get my node:alpine Docker image for a react/next.js to build.</p>
  <p>I can get it to build fine locally, but I never see the traffic in my API logs when the Docker build reaches out to the API endpoint, which is itself running in a Docker container (nginx, headless craft cms, etc.).</p>
  <p>The build does not seem to like localhost at all, as I've tried:</p>
  <p>http://localhost:9000/api</p>
  <p>...and this is the message I get in the logs:</p>
  <pre><code>#15 13.76 &gt; Build error occurred
  #15 13.76 FetchError: request to http://localhost:9000/api failed, reason: connect ECONNREFUSED 127.0.0.1:9000
  </code></pre>
  <p>I've heard that I can use the hostname in place of &quot;localhost&quot;, so in my MacOS terminal I've typed &quot;hostname&quot; and I've swapped out the localhost for this value. This doesn't outright error out, but the build hangs on the &quot;Generating pages...&quot; step of the build.</p>
  <p>How can I get the Docker build to recognize localhost, or put another way, how can I set my API URL to an endpoint hosted by a local Docker container?</p>
  <p>Here is my Dockerfile:</p>
  <pre><code># Install dependencies only when needed
  FROM node:alpine AS deps
  RUN apk add --no-cache libc6-compat
  WORKDIR /app
  COPY package.json yarn.lock ./
  RUN yarn --frozen-lockfile
  
  # Rebuild the source code only when needed
  FROM node:alpine AS builder
  
  WORKDIR /app
  COPY . .
  COPY --from=deps /app/node_modules ./node_modules
  RUN yarn static
  
  # Production image, copy all the files and run next
  FROM node:alpine AS runner
  WORKDIR /app
  
  ENV NODE_ENV production
  
  RUN addgroup -g 1001 -S nodejs
  RUN adduser -S nextjs -u 1001
  
  # You only need to copy next.config.js if you are NOT using the default configuration
  COPY --from=builder /app/public ./public
  COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
  COPY --from=builder /app/node_modules ./node_modules
  COPY --from=builder /app/package.json ./package.json
  
  USER nextjs
  
  EXPOSE 3000
  
  # Next.js collects completely anonymous telemetry data about general usage.
  # Learn more here: https://nextjs.org/telemetry
  # Uncomment the following line in case you want to disable telemetry.
  # ENV NEXT_TELEMETRY_DISABLED 1
  
  CMD [&quot;yarn&quot;, &quot;start&quot;]
  </code></pre>