Docker镜像构建失败后台进程的错误响应



我正在用nginx镜像构建Angular应用程序,同时创建Docker构建步骤Jenkins构建失败,错误消息如下。你能帮我解释一下为什么Docker不允许我构建图像吗

Docker文件

# base image
FROM node:13.3.0 AS build
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
# add app
COPY . /app
FROM nginx
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html

接下来是构建docker图像的jnkinsfile阶段

stage('Build Docker Image') {
container('docker') {
echo 'docker'
sh "docker build -t username/${image_name}:${image_tag} ."
sh "docker tag ${image_name} ${image_name}:${image_tag}"           
}
}

詹金斯构建日志

[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build Docker Image)
[Pipeline] container
[Pipeline] {
[Pipeline] echo
docker
[Pipeline] sh
+ docker build -t username/frontend-app:master-49089c41 .
Sending build context to Docker daemon 557.1 kB
Sending build context to Docker daemon 1.114 MB
Sending build context to Docker daemon 1.671 MB
Sending build context to Docker daemon 2.228 MB
Step 1/9 : FROM node:13.3.0 AS build
---> 2af77b226ea7
Step 2/9 : WORKDIR /app
---> Using cache
---> afd7b5b6b236
Step 3/9 : ENV PATH /app/node_modules/.bin:$PATH
---> Using cache
---> 2b2a5ea72fe1
Step 4/9 : COPY package.json /app/package.json
---> Using cache
---> a7c4dbcd6421
Step 5/9 : RUN npm install
---> Using cache
---> 281815d7cd02
Step 6/9 : COPY . /app
---> f1ef0f9eebe1
Step 7/9 : FROM nginx
---> 62d49f9bab67
Step 8/9 : COPY nginx.conf /etc/nginx/conf.d/default.conf
---> Using cache
---> a53597248ccf
Step 9/9 : COPY --from=build /app/dist /usr/share/nginx/html
---> d85d9b9cda00
Successfully built d85d9b9cda00
Successfully tagged username/frontend-app:master-49089c41
[Pipeline] sh
+ docker tag frontend-app frontend-app:master-49089c41
Error response from daemon: No such image: frontend-app:latest

docker tag命令中,您试图使用不存在的源映像。您需要指定图像的全名,在您的情况下使用username和刚刚创建的标签。这里发生的事情是Docker试图找到具有默认标记(最新(的frontend-app,但您应该指示它查找frontend-app:master-49089c41

试着把它改成这样:

stage('Build Docker Image') {
container('docker') {
echo 'docker'
sh "docker build -t username/${image_name}:${image_tag} ."
sh "docker tag username/${image_name}:${image_tag} ${image_name}:${image_tag}"           
}
}

最新更新