Dav*_*lva 2 docker dockerfile minikube
我有为 Angular 应用程序编写的 Dockerfile:
#### 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;"]
Run Code Online (Sandbox Code Playgroud)
我可以在我的机器上很好地构建这个图像docker build -t my-angular-app:v1 .
但是如果我首先eval $(minikube docker-env)
使用 minikube 的 docker 守护进程而不是本地的 docker 守护进程并执行相同的命令:(docker build -t my-angular-app:v1 .
按照README中的说明)
我收到以下错误(没有此类文件或目录):
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
Run Code Online (Sandbox Code Playgroud)
事实上,虚拟机中没有文件夹 /var/lib/docker/overlay2/2972c4... 。
我错过了什么 ?
我正在使用 minikube v1.6.2 和 virtualbox v5.2.34
本地docker v19.03.5
minikube的docker也是v19.03.5
FIYminikube docker-env
设置以下环境变量:
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/myUser/.minikube/certs"
Run Code Online (Sandbox Code Playgroud)
好吧,我发现了这个问题:它与我的 Dockerfile 或 minikube 中丢失的文件无关。
TLDR 在最后。
所以问题是 Docker 找不到第一阶段创建的 /app/dist/MyAngularApp 文件夹。
该文件夹应该由命令创建npm run build:prod
。
当用我的机器构建时,它可以工作。通过 minikube 构建时,不会创建该文件夹。没有错误或警告。该命令运行...但没有任何结果。
有人建议使用 Yarn 而不是 Npm,看看它是否显示某种错误或警告。答对了!
yarn run build:prod
显示:error Command failed with signal "SIGKILL".
哈哈!构建占用了太多资源并被终止。
我用以下命令提高了 minikube 上的内存:
minikube delete;
minikube start --memory 4096
Run Code Online (Sandbox Code Playgroud)
现在效果很好!
我不知道为什么 Yarn 显示错误而 Npm 没有,即使使用 --verbose 也是如此。
太长了;minikube 内存不足导致它 SIGKILL 我的npm build
. 没有构建,没有生成的文件夹,因此出现复制错误。使用 npm 时没有显示错误。切换到 Yarn,它显示 SIGKILL 错误。
归档时间: |
|
查看次数: |
8713 次 |
最近记录: |