Building a Nuxt project using Docker only fails in the BitBucket pipeline
Asked by bweber:

I have a project I am building that uses Vue with Vite and Nuxt. The project uses Docker, and the docker container builds completely normally in my local environment. When I try to build the docker container in the bitbucket pipeline environment, it fails every time. I have tried many different solutions around allocating space, but they haven't made a difference. I also can't find any way to get a more detailed error log, so the only error I'm left with tells me nothing. I also have tried making my environment as close to the bitbucket pipelines as I can, but every build still works locally. I'm left with these questions:

1) How can I get a more helpful error log?

2) Are there any tools for replicating the bitbucket pipeline environment on my computer so I can reproduce the problem locally?

3) Why would a docker build work locally but not in the bitbucket pipeline? Isn't the point of docker that it works in every environment? (My best lead at the moment is that they use two different networks, but I don't know how that would change anything)

*** ** * ** ***

This is my Docker file:

# Declare the base image  
FROM node:18-alpine

# Build step  
# 1. copy package.json and package-lock.json to /app dir  
RUN mkdir /app  
COPY ./package\*.json /app/

# 2. Change working directory to newly created app dir  
WORKDIR /app

# 3 . Install dependencies  
RUN npm cache clean --force \&\& npm install

# 4. Copy the source code to /app dir  
COPY . .

# 5. Build the app  
RUN npm run build

# 6. Expose port 4173 on the container  
EXPOSE 4173

# 7. Run the app  
CMD \["npm", "run", "preview"\]  

*** ** * ** ***

This is the relevant error log in the bitbucket pipeline:  
#4 \[9/9\] RUN npm run build  
#4 sha256:0fe8ab14dc2301ac8aaaf368f0a3e3be4bdb196f812e8b09835bf029f0b62ccd  
#4 0.529  
#4 0.529 \> curator@0.0.0 build  
#4 0.529 \> cross-env NUXT_APP_BASE_URL=/curator-ui/ nuxt build --verbose  
#4 0.529  
#4 0.914 Nuxt 3.11.2 with Nitro 2.9.6  
#4 4.763 ? Building client...  
#4 4.779 ? vite v5.2.8 building for production...  
#4 4.823 ? transforming...  
#4 16.33 ? ? 854 modules transformed.  
#4 16.78 Inspect report generated at /app/.nuxt/analyze/.vite-inspect  
#4 17.44 ? rendering chunks...  
#4 18.05 ? computing gzip size...  
#4 18.19 ? .nuxt/dist/client/manifest.json 10.12 kB ? gzip: 1.49 kB  
#4 18.19 ? .nuxt/dist/client/_nuxt/LoadingOverlay.CN2Vr0U1.css 0.08 kB ? gzip: 0.10 kB  
... This continues with a bunch of nuxt items ...  
#4 18.23 ? .nuxt/dist/client/_nuxt/C47_dAMR.js 535.55 kB ? gzip: 175.07 kB  
#4 18.23 ? .nuxt/dist/client/_nuxt/DrsPblm4.js 917.27 kB ? gzip: 305.09 kB  
#4 18.23 ? ? built in 13.46s  
#4 18.24 ? Client built in 13472ms  
#4 18.24 ? Building server...  
#4 18.24 ? vite v5.2.8 building SSR bundle for production...  
#4 18.35 ? transforming...  
#4 30.21 ? ? 713 modules transformed.  
#4 31.25 Inspect report generated at /app/.nuxt/analyze/.vite-inspect  
#4 32.45 ? rendering chunks...  
#4 33.29 ? .nuxt/dist/server/_nuxt/_id_-styles.CNX6znJC.mjs 0.08 kB  
#4 33.29 ? .nuxt/dist/server/_nuxt/_id_-styles.aREm4Hto.mjs 0.08 kB  
... This continues with a bunch of chunks ...  
#4 33.41 ? .nuxt/dist/server/_nuxt/entry-styles-1.mjs-Cf-N_X7E.js 242.99 kB ? map: 0.11 kB  
#4 33.41 ? .nuxt/dist/server/server.mjs 790.34 kB ? map: 1,596.65 kB  
#4 33.41 ? ? built in 15.17s  
#4 33.43 ? Server built in 15191ms  
#4 33.53 \[nitro\] ? Generated public .output/public  
#4 33.54 \[nitro\] ? Building Nuxt Nitro server (preset: node-server)  
#4 200.8 \[nitro\] ? Nuxt Nitro server built  
#4 ERROR: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1  
------  
\> \[9/9\] RUN npm run build:  
------  
process "/bin/sh -c npm run build" did not complete successfully: exit code: 1  

*** ** * ** ***

On a successful local build, the logs will continue at the error point by listing all the chunks built by the nitro server, giving the total size, and showing a command for previewing the application.  


Answers:
author: Patrik S
body: Hey [@bweber](/t5/user/viewprofilepage/user-id/5506737) ,

and welcome to the Community!

By reading your description, I understand the error is happening during a Docker build. The Docker build is executed in a separate container (docker service container) from the build container (where the script runs) and has its own memory allocated to it.

I suspect you may be using the default memory allocated to docker service, which is 1GB, and this is not being enough for the *npm command* to complete, hence causing your build to fail.

For that, I would suggest that you increase the memory for the docker service by adding the following definition to your YML file :

```
definitions:
  services:
    docker:
      memory: 2048
```

This would make 2GB of memory available for the docker service. You can start with 2GB and increase it as needed.

Considering that the docker service is the only service in your step, in normal steps you can increase the size of the docker service up to 3GB, while in large steps ([size: 2x](https://support.atlassian.com/bitbucket-cloud/docs/step-options/#Size)), it can be defined as up to 7GB.

For more details on how memory is allocated between the build and service containers, I would also recommend checking the following documentation:

* [Bitbucket Pipelines - Databases and Service containers](https://support.atlassian.com/bitbucket-cloud/docs/databases-and-service-containers/)

I hope that helps! Let us know in case you have any questions.

Thank you, [@bweber](/t5/user/viewprofilepage/user-id/5506737) !

Patrik S

comments: author: bweber
body: Hi Patrik,

Thank you for the welcome!

The solution you proposed ended up working! Thank you so much. I have spent countless hours running in circles over this, and I really appreciate you taking the time to respond.

Thanks again!

Braden


author: Patrik S
body: Hey [@bweber](/t5/user/viewprofilepage/user-id/5506737) ,

You're very welcome!

Happy to hear that increasing the docker memory did the trick :)

Feel free to reach out to the Community if you ever need help in the future.

Have a great day, [@bweber](/t5/user/viewprofilepage/user-id/5506737) !

Patrik S


Tags: bitbucket-cloud

bitbucket-pipelines

cloud

docker

nuxt