Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,455,797
Community Members
 
Community Events
176
Community Groups

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

Atlassian Community Events