Error: failed to fetch an image or build from source: error building: failed to solve

I have added RUN apt-get update in my Dockerfile, and on deployment, it’s throwing this error: Error: failed to fetch an image or build from source: error building: failed to solve: process "/bin/sh -c apt-get clean && apt-get update did not complete successfully: exit code: 127

Has anyone experienced this problem?

Here is how I deploy the code in Git CI/CD: flyctl deploy --config ./fly.us.toml --wait-timeout 1200 --local-only ${buildArgs}

And my Docker image is: node:16-alpine

Have you considered letting us generate a Dockerfile for you? fly launch will provide one or you can run our dockerfile generator standalone: GitHub - fly-apps/dockerfile-node: Dockerfile generator for Node.js

I’m guessing that you have a Dockerfile that was formed by gathering up pieces from various sources. apt is for use with Debian based operating systems; apk is what you would use with alpine.

Our dockerfile generator defaults to the base node images, and therefore Debian, but provides --alpine as an option.

hi @rubys Thanks, but I’m not sure I understand what you mean specifically. I have a custom Dockerfile where I install the necessary libraries.

Here is my docker file:

# Use an official Node.js runtime as a parent image

FROM node:16-alpine

# Set the working directory

WORKDIR .

# Install Python, make, and g++ for building native dependencies

RUN apk --no-cache add python3 make g++

# Copy package.json and package-lock.json (or yarn.lock)

COPY package.json package-lock.json ./

# Install dependencies and rebuild bcrypt

RUN npm install --legacy-peer-deps && npm rebuild bcrypt --build-from-source

# Install Puppeteer globally

RUN npm install -g puppeteer

# Install Chromium and its dependencies

# Update the package list

RUN apt-get update

# Install Chromium

#RUN apt-get install -y chromium

# Copy the rest of your app's source code

COPY . .

# Arguments passed via --build-arg are converted to environment variables

ARG PORT
ARG X_API_KEY

# Set them as environment variables

ENV PORT=${PORT}
ENV X_API_KEY=${X_API_KEY}

# Build your app

RUN npm run build

# Expose the port the app runs on

EXPOSE 5001

# Command to run your app

CMD ["npm", "run", "start:prod"]

You’re using alpine

But you’re using the wrong command: apt-get instead of apk.
Also, use node-20+ man

2 Likes

Thanks @khuezy it’s very helpful!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.