title: Building docker image of nuxt application using github actions fails (heap memory size exceeded)
body: <p>I am trying to setup Github Actions workflow to automatically build and push docker image of my nuxt app,</p>
  <p>When the workflow finishes and I pull the image and run it, the web application doesn't load and memory consumption starts getting higher and higher until the docker container stops with the following error.</p>
  <blockquote>
  <p>&lt;--- Last few GCs ---&gt;</p>
  </blockquote>
  <blockquote>
  <p>[28:0x7f75bc1ae310]   730417 ms: Mark-sweep (reduce) 2040.7 (2083.0) -&gt; 2039.5 (2083.2) MB, 4274.1 / 0.5 ms  (average mu = 0.200, current mu = 0.163) allocation failure scavenge might not succeed
  [28:0x7f75bc1ae310]   734992 ms: Mark-sweep (reduce) 2040.6 (2083.2) -&gt; 2039.7 (2083.2) MB, 4549.0 / 0.5 ms  (average mu = 0.112, current mu = 0.006) allocation failure scavenge might not succeed</p>
  </blockquote>
  <blockquote>
  <p>&lt;--- JS stacktrace --&gt;</p>
  </blockquote>
  <blockquote>
  <p>FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
  info Visit <a href="https://yarnpkg.com/en/docs/cli/run" rel="nofollow noreferrer">https://yarnpkg.com/en/docs/cli/run</a> for documentation about this command.
  error Command failed with signal &quot;SIGABRT&quot;.</p>
  </blockquote>
  <p>I did an strace of my container's process and this portion kept repeating infinitely (a network call for an API endpoint I am calling in my application &quot;GET /tags/active&quot;)</p>
  <pre><code>write(42261, &quot;GET /tags/active HTTP/1.1\r\nAccep&quot;..., 797) = 797
  getsockopt(42262, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
  write(42262, &quot;GET /tags/active HTTP/1.1\r\nAccep&quot;..., 778) = 778
  epoll_ctl(13, EPOLL_CTL_ADD, 42263, {events=EPOLLIN, data={u32=42263, u64=42263}}) = 0
  epoll_ctl(13, EPOLL_CTL_ADD, 42264, {events=EPOLLIN, data={u32=42264, u64=42264}}) = 0
  epoll_ctl(13, EPOLL_CTL_ADD, 42261, {events=EPOLLIN, data={u32=42261, u64=42261}}) = -1 EEXIST (File exists)
  epoll_ctl(13, EPOLL_CTL_MOD, 42261, {events=EPOLLIN, data={u32=42261, u64=42261}}) = 0
  epoll_ctl(13, EPOLL_CTL_ADD, 42262, {events=EPOLLIN, data={u32=42262, u64=42262}}) = -1 EEXIST (File exists)
  epoll_ctl(13, EPOLL_CTL_MOD, 42262, {events=EPOLLIN, data={u32=42262, u64=42262}}) = 0
  epoll_pwait(13, [{events=EPOLLIN, data={u32=42263, u64=42263}}, {events=EPOLLIN, data={u32=42264, u64=42264}}], 1024, 0, NULL, 8) = 2
  read(42263, &quot;GET /tags/active HTTP/1.1\r\nAccep&quot;..., 65536) = 797
  futex(0x7f75b35e69a4, FUTEX_WAKE_PRIVATE, 1) = 1
  futex(0x557c4d5da464, FUTEX_WAKE_PRIVATE, 1) = 1
  read(42264, &quot;GET /tags/active HTTP/1.1\r\nAccep&quot;..., 65536) = 778
  futex(0x7f75b25e09a4, FUTEX_WAKE_PRIVATE, 1) = 1
  futex(0x557c4d5da464, FUTEX_WAKE_PRIVATE, 1) = 1
  epoll_pwait(13, [{events=EPOLLIN, data={u32=16, u64=16}}], 1024, 0, NULL, 8) = 1
  read(16, &quot;\1\0\0\0\0\0\0\0&quot;, 1024)      = 8
  futex(0x7f75b2de39a4, FUTEX_WAKE_PRIVATE, 1) = 1
  futex(0x557c4d5da464, FUTEX_WAKE_PRIVATE, 1) = 1
  futex(0x7f75b1ddd9a4, FUTEX_WAKE_PRIVATE, 1) = 1
  futex(0x557c4d5da464, FUTEX_WAKE_PRIVATE, 1) = 1
  epoll_pwait(13, [{events=EPOLLIN, data={u32=16, u64=16}}], 1024, 0, NULL, 8) = 1
  read(16, &quot;\1\0\0\0\0\0\0\0&quot;, 1024)      = 8
  socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 42265
  connect(42265, {sa_family=AF_INET, sin_port=htons(3000), sin_addr=inet_addr(&quot;127.0.0.1&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)
  socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 42266
  connect(42266, {sa_family=AF_INET, sin_port=htons(3000), sin_addr=inet_addr(&quot;127.0.0.1&quot;)}, 16) = -1 EINPROGRESS (Operation now in progress)
  epoll_ctl(13, EPOLL_CTL_ADD, 42265, {events=EPOLLOUT, data={u32=42265, u64=42265}}) = 0
  epoll_ctl(13, EPOLL_CTL_ADD, 42266, {events=EPOLLOUT, data={u32=42266, u64=42266}}) = 0
  epoll_pwait(13, [{events=EPOLLIN, data={u32=18, u64=18}}, {events=EPOLLOUT, data={u32=42265, u64=42265}}, {events=EPOLLOUT, data={u32=42266, u64=42266}}], 1024, 0, NULL, 8) = 3
  accept4(18, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 42267
  getpeername(42267, {sa_family=AF_INET, sin_port=htons(35257), sin_addr=inet_addr(&quot;127.0.0.1&quot;)}, [128 =&gt; 16]) = 0
  accept4(18, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 42268
  getpeername(42268, {sa_family=AF_INET, sin_port=htons(35259), sin_addr=inet_addr(&quot;127.0.0.1&quot;)}, [128 =&gt; 16]) = 0
  accept4(18, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable)
  getsockopt(42265, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
  write(42265, &quot;GET /tags/active HTTP/1.1\r\nAccep&quot;..., 797) = 797
  getsockopt(42266, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
  write(42266, &quot;GET /tags/active HTTP/1.1\r\nAccep&quot;..., 778) = 778
  </code></pre>
  <p><strong>This is my Dockerfile</strong></p>
  <pre><code>FROM node:alpine as builder
  
  
  WORKDIR /app
   
  RUN apk update &amp;&amp; apk upgrade &amp;&amp; apk add git
   
  COPY package.json yarn.lock ./
   
  RUN yarn install \
    --prefer-offline \
    --frozen-lockfile \
    --non-interactive \
    --production=false
   
  COPY . .
   
  RUN --mount=type=secret,id=MOUHIM_API_URL \
      --mount=type=secret,id=GOOGLE_CLIENT_ID \
        --mount=type=secret,id=GOOGLE_REDIRECT_URI \
          --mount=type=secret,id=FACEBOOK_CLIENT_ID \
            --mount=type=secret,id=FACEBOOK_REDIRECT_URI \
             export MOUHIM_API_URL=$(cat /run/secrets/MOUHIM_API_URL) &amp;&amp; \
             export GOOGLE_CLIENT_ID=$(cat /run/secrets/GOOGLE_CLIENT_ID) &amp;&amp; \
             export GOOGLE_REDIRECT_URI=$(cat /run/secrets/GOOGLE_REDIRECT_URI) &amp;&amp; \
             export FACEBOOK_CLIENT_ID=$(cat /run/secrets/FACEBOOK_CLIENT_ID) &amp;&amp; \
             export FACEBOOK_REDIRECT_URI=$(cat /run/secrets/FACEBOOK_REDIRECT_URI) &amp;&amp; \
             yarn build &amp;&amp; \
             rm -rf node_modules
   
  RUN NODE_ENV=production yarn install \
    --prefer-offline \
    --pure-lockfile \
    --non-interactive \
    --production=true
   
  FROM node:alpine
   
  WORKDIR /app
   
  COPY --from=builder /app  .
   
  ENV HOST 0.0.0.0
  EXPOSE 3000
   
  CMD [ &quot;yarn&quot;, &quot;start&quot; ]
  </code></pre>
  <p><strong>this is my Github Workflow yml file</strong></p>
  <pre><code>name: Docker
   
  # This workflow uses actions that are not certified by GitHub.
  # They are provided by a third-party and are governed by
  # separate terms of service, privacy policy, and support
  # documentation.
   
  on:
    push:
      branches: [ master ]
      # Publish semver tags as releases.
      tags: [ 'v*.*.*' ]
    pull_request:
      branches: [ master ]
   
   
  env:
    # Use docker.io for Docker Hub if empty
    REGISTRY: ghcr.io
    # github.repository as &lt;account&gt;/&lt;repo&gt;
    IMAGE_NAME: ${{ github.repository }}
   
  jobs:
    build:
      runs-on: ubuntu-latest
      permissions:
        contents: read
        packages: write
   
      steps:
        - name: Checkout repository
          uses: actions/checkout@v2
   
        # Login against a Docker registry except on PR
        # https://github.com/docker/login-action
        - name: Log into registry ${{ env.REGISTRY }}
          if: github.event_name != 'pull_request'
          uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
          with:
            registry: ${{ env.REGISTRY }}
            username: ${{ github.actor }}
            password: ${{ secrets.GITHUB_TOKEN }}
   
        # Extract metadata (tags, labels) for Docker
        # https://github.com/docker/metadata-action
        - name: Extract Docker metadata
          id: meta
          uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
          with:
            images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
   
        # Build and push Docker image with Buildx (don't push on PR)
        # https://github.com/docker/build-push-action
        - name: Build and push Docker image
          uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
          with:
            context: .
            push: ${{ github.event_name != 'pull_request' }}
            tags: ${{ steps.meta.outputs.tags }}
            labels: ${{ steps.meta.outputs.labels }}
            secrets: |
              &quot;MOUHIM_API_URL=https://example.com/api&quot;
              &quot;GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}&quot;
              &quot;GOOGLE_REDIRECT_URI=${{ secrets.GOOGLE_REDIRECT_URI }}&quot;
              &quot;FACEBOOK_CLIENT_ID=${{ secrets.FACEBOOK_CLIENT_ID }}&quot;
              &quot;FACEBOOK_REDIRECT_URI=${{ secrets.FACEBOOK_REDIRECT_URI }}&quot;
  </code></pre>