Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Docker build fails in the pipeline with npm error while builds local builds successfully

My docker file which is building successfully local, is as following 

FROM node:14.1-alpine AS builder

COPY . /opt/web

WORKDIR /opt/web

RUN npm install

RUN npx browserslist@latest --update-db

ENV PATH=“/opt/web/node_modules/.bin:$PATH

RUN npm run build

FROM nginx:1.17-alpine

RUN apk --no-cache add curl

COPY --from=builder /opt/web/build /usr/share/nginx/html

RUN chgrp -R 0 /var/* && chmod -R g=u /var/*

CMD [“nginx”, “-g”, “daemon off;“]
When I run the same docker file for the build throught he pipeline, I am getting following error. 
error.png
My bitbucket pipeline yml file is as following, I did try both atlassian/default-image:3 and node image, however getting same error. 

# Template docker-push

# This template allows you to build and push your docker image to a Docker Hub account.

# The workflow allows running tests, code linting and security scans on feature branches (as well as master).

# The docker image will be validated and pushed to the docker registry after the code is merged to master.

# Prerequisites: $DOCKERHUB_USERNAME, $DOCKERHUB_PASSWORD setup as deployment variables

# image: atlassian/default-image:3

image: node:14.1-alpine

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- IMAGE_NAME=$BITBUCKET_REPO_SLUG

- docker build . --file Dockerfile --tag ${IMAGE_NAME}

- docker save ${IMAGE_NAME} --output “${IMAGE_NAME}.tar”

services:

- docker

caches:

- docker

artifacts:

- “*.tar”

2 answers

1 accepted

0 votes
Answer accepted

The final solution, which worked for me was to unset the CI before running the npm run build, along with using the npm in the bitbucket pipeline, instead of the docker file. 

Here I am pasting my updated pipeline, for the successfull build 

 

image: atlassian/default-image:3

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- npm cache clean --force

- rm -rf node_modules

- npm install

- unset CI

- npm run build

- IMAGE_NAME=${BITBUCKET_REPO_SLUG}

- docker build . --file Dockerfile --tag ${IMAGE_NAME}

- docker save ${IMAGE_NAME} --output "${IMAGE_NAME}.tar"

services:

- docker

caches:

- docker

artifacts:

- "*.tar"

Thanks @r_abbasi  it works

@r_abbasi hi. Do you have warnings in your local build?  This was pointed here: https://stackoverflow.com/a/58701621

Regards, Igor.

Like r_abbasi likes this

@Igor Stoyanov  Yeh, I had warnings in the build.  Thanks for the support. 

@r_abbasi hi. Thanks for your question. Try to follow Build and push a Docker image guide.

Also the suggestion is not to use node:14.1-alpine, because alpine is minimalistic, instead use the image node:14.1

Regards, Igor

I am getting the same error for the following very simple pipeline

 

image: node:14.17.6

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- npm install

- npm run build

ok, Thanks @Igor Stoyanov . I am trying the first comment, as the second one isn't valid in my case. 

I am still getting the same error, while the build is successfull locally. Looks like something wrong with the bitbucket pipeline for node containerized app. look at the updated pipeline file. 

 

image: node:16.13.1

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- IMAGE_NAME=$BITBUCKET_REPO_SLUG

- docker build . --file Dockerfile --tag ${IMAGE_NAME}

- docker save ${IMAGE_NAME} --output “${IMAGE_NAME}.tar”

services:

- docker

caches:

- docker

artifacts:

- “*.tar”

@ hi. Since you do not use npm in bitbucket-pipeline.yml use 

image: atlassian/default-image:3

also check and update commands inside your Dockerfile according to https://stackoverflow.com/questions/42308879/how-to-solve-npm-error-npm-err-code-elifecycle

I did follow that as well, but didn't work. Looks like some conflict between node and bitbucket pipelines. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

218 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you