DavidDaSilva
DavidDaSilva

Reputation: 111

Error when building docker multi-stage image through minikube : file not found

I've got this Dockerfile I wrote for an Angular App :

#### Stage 1: Build the angular application
FROM node:12.4.0-alpine as build

# Configure the main working directory inside the docker image.
# This is the base directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
WORKDIR /app

# Copy the package.json as well as the package-lock.json and install
# the dependencies. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY package.json package-lock.json ./
RUN npm ci
RUN npm install -g @angular/cli

# Copy the main application
COPY . ./

# Build the application
RUN npm run build:prod

#### Stage 2: Serve the Angular application from Nginx
FROM nginx:1.17.0-alpine

RUN rm -rf /usr/share/nginx/html/*

# Copy the angular build from Stage 1
COPY --from=build /app/dist/MyAngularApp /usr/share/nginx/html

# Copy our custom nginx config
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
COPY nginx/status.conf /etc/nginx/conf.d/status.conf

# Expose port 80 to the Docker host, so we can access it
# from the outside.
EXPOSE 80
# Expose port 8081 to the Docker host, for nginx status pages
EXPOSE 8081

ENTRYPOINT ["nginx","-g","daemon off;"]

I can build this image just fine on my machine with docker build -t my-angular-app:v1 .

But if I do first eval $(minikube docker-env) to use the docker daemon of minikube instead of my local and execute the same command : docker build -t my-angular-app:v1 . (as instructed in README )

I get the following error (no such file or directory):

Step 10/15 : COPY --from=build /app/dist/MyAngularApp /usr/share/nginx/html
COPY failed: stat /var/lib/docker/overlay2/2972c4790d70a2e0c98895855e5bde894a97ebab8c5a8b2efab5100c3f8c6fbb/merged/app/dist/MyAngularApp: no such file or directory

Indeed, there is no folder /var/lib/docker/overlay2/2972c4... in the VM.

What did I miss ?

I'm using minikube v1.6.2 with virtualbox v5.2.34

local docker v19.03.5

minikube's docker is also v19.03.5

FIY minikube docker-env sets the following env variables :

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/myUser/.minikube/certs"

Upvotes: 2

Views: 9096

Answers (2)

DavidDaSilva
DavidDaSilva

Reputation: 111

Okay I found the issue : it has nothing to do with my Dockerfile or missing files in minikube.

TLDR at the end.

So the problem is that Docker does not find the /app/dist/MyAngularApp folder created during the first stage.

This folder is supposed to be created by the command npm run build:prod.

When building with my machine, it works. When building via minikube, the folder is not created. No error or warnings. The command runs... and nothing.

Somebody suggested using Yarn instead of Npm, to see if it shows some kind of error or warning. Bingo!

yarn run build:prod shows : error Command failed with signal "SIGKILL".

Haha! The build takes too much resources and gets killed.

I upped the memory on minikube with :

minikube delete;
minikube start --memory 4096

And now it works fine!

I don't know why Yarn shows the error and Npm does not, even with --verbose.

TLDR; Insuficient memory on minikube caused it to SIGKILL my npm build. No build, no resulting folder, hence the COPY error. No error shown when using npm. Switched to Yarn and it shows the SIGKILL error.

Upvotes: 9

Piotr Malec
Piotr Malec

Reputation: 3647

As noted in comments this is caused by files needed to build image not being found on VM host that is running minikube.

To get Your files to minikube VM You can use command minikube ssh and then use scp or any other bash command to copy the files where they need to be.

Upvotes: 0

Related Questions