使用 Dockerfile 文件但是不使用缓存生成镜像
前一段时候使用 Dockerfile 重新部署 NetCore3.1 项目的时候很顺利,由来由于一些原因,我把以前的镜像删除,如果我们大家继续使用 docker build 命令去生成镜像的话就会报错,例如:
1 [root@localhost PatrickLiu.NetCore]# docker build -t core31v1.112 -f Dockerfile .
2 Sending build context to Docker daemon 4.425MB
3 Step 1/17 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
4 ---> e3559b2d50bb
5 Step 2/17 : WORKDIR /app
6 ---> Using cache
7 ---> 1c0ab1a505e2
8 Step 3/17 : EXPOSE 80
9 ---> Using cache
10 ---> 49a72547d567
11 Step 4/17 : EXPOSE 443
12 unable to find image "sha256:c5ed536f38a6742b7c084fa87e6ac885d9697960a20860f7fd0299da578cf2c8"
这样肯定是不行的,我们肯定希望使用没有缓存的方式重新加载文件生成镜像,怎么做呢?
问题
你想不用缓存重建Dockerfile。
解决方法
构建镜像时使用 --no-cache 参数。
讨论
为了强制docker构建镜像时不用缓存,执行带–no-cache参数的docker build命令。下面的示例是使用了–no-cache构建镜像。
效果如下:
1 [root@localhost PatrickLiu.NetCore]# docker build --no-cache -t core31v1.112 -f Dockerfile .
2 Sending build context to Docker daemon 4.425MB
3 Step 1/17 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
4 ---> e3559b2d50bb
5 Step 2/17 : WORKDIR /app
6 ---> Running in e8178063fe45
7 Removing intermediate container e8178063fe45
8 ---> 0a1d582b30d4
9 Step 3/17 : EXPOSE 80
10 ---> Running in e7716f388165
11 Removing intermediate container e7716f388165
12 ---> fc54a6e3c0aa
13 Step 4/17 : EXPOSE 443
14 ---> Running in 449680497b7f
15 Removing intermediate container 449680497b7f
16 ---> acf106867ca0
17 Step 5/17 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
18 3.1-buster: Pulling from dotnet/core/sdk
19 e4c3d3e4f7b0: Pull complete
20 101c41d0463b: Pull complete
21 8275efcd805f: Pull complete
22 751620502a7a: Pull complete
23 8e306865fd07: Pull complete
24 9d2f53e752c2: Downloading [===========================> ] 69.19MB/123.8MB
25 143a93e01eba: Download complete
镜像文件重新生成,没有使用缓存,每天进步一点点,把问题记录下来,这就是成长了。继续努力。
镜像最后生成的胜利步骤。
1 [root@localhost PatrickLiu.NetCore]# docker build --no-cache -t core31v1.112 -f Dockerfile .
2 Sending build context to Docker daemon 4.425MB
3 Step 1/17 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
4 ---> e3559b2d50bb
5 Step 2/17 : WORKDIR /app
6 ---> Running in e8178063fe45
7 Removing intermediate container e8178063fe45
8 ---> 0a1d582b30d4
9 Step 3/17 : EXPOSE 80
10 ---> Running in e7716f388165
11 Removing intermediate container e7716f388165
12 ---> fc54a6e3c0aa
13 Step 4/17 : EXPOSE 443
14 ---> Running in 449680497b7f
15 Removing intermediate container 449680497b7f
16 ---> acf106867ca0
17 Step 5/17 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
18 3.1-buster: Pulling from dotnet/core/sdk
19 e4c3d3e4f7b0: Pull complete
20 101c41d0463b: Pull complete
21 8275efcd805f: Pull complete
22 751620502a7a: Pull complete
23 8e306865fd07: Pull complete
24 9d2f53e752c2: Pull complete
25 143a93e01eba: Pull complete
26 Digest: sha256:bfd6083e9cd36b37b2a4e9f1722cc958b6654fa96cb3d84ef78492ecf00dcd32
27 Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:3.1-buster
28 ---> 5fe503d51830
29 Step 6/17 : WORKDIR /src
30 ---> Running in 4312c5d63f3f
31 Removing intermediate container 4312c5d63f3f
32 ---> 31cfbe6739ec
33 Step 7/17 : COPY ["PatrickLiu.NetCore.MvcDemo/PatrickLiu.NetCore.MvcDemo.csproj", "PatrickLiu.NetCore.MvcDemo/"]
34 ---> ba9ba79cc7d3
35 Step 8/17 : RUN dotnet restore "PatrickLiu.NetCore.MvcDemo/PatrickLiu.NetCore.MvcDemo.csproj"
36 ---> Running in 8d2c9ee24614
37 Determining projects to restore...
38 Restored /src/PatrickLiu.NetCore.MvcDemo/PatrickLiu.NetCore.MvcDemo.csproj (in 4.64 sec).
39 Removing intermediate container 8d2c9ee24614
40 ---> 872cce519821
41 Step 9/17 : COPY . .
42 ---> 4fe062b14ab1
43 Step 10/17 : WORKDIR "/src/PatrickLiu.NetCore.MvcDemo"
44 ---> Running in 431b1c2f4959
45 Removing intermediate container 431b1c2f4959
46 ---> b9dc3acf883c
47 Step 11/17 : RUN dotnet build "PatrickLiu.NetCore.MvcDemo.csproj" -c Release -o /app/build
48 ---> Running in 639b5e3d01df
49 Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
50 Copyright (C) Microsoft Corporation. All rights reserved.
51
52 Determining projects to restore...
53 All projects are up-to-date for restore.
54 PatrickLiu.NetCore.MvcDemo -> /app/build/PatrickLiu.NetCore.MvcDemo.dll
55 PatrickLiu.NetCore.MvcDemo -> /app/build/PatrickLiu.NetCore.MvcDemo.Views.dll
56
57 Build succeeded.
58 0 Warning(s)
59 0 Error(s)
60
61 Time Elapsed 00:00:19.21
62 Removing intermediate container 639b5e3d01df
63 ---> aeb1df18b3f6
64 Step 12/17 : FROM build AS publish
65 ---> aeb1df18b3f6
66 Step 13/17 : RUN dotnet publish "PatrickLiu.NetCore.MvcDemo.csproj" -c Release -o /app/publish
67 ---> Running in ac663a5be455
68 Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
69 Copyright (C) Microsoft Corporation. All rights reserved.
70
71 Determining projects to restore...
72 All projects are up-to-date for restore.
73 PatrickLiu.NetCore.MvcDemo -> /src/PatrickLiu.NetCore.MvcDemo/bin/Release/netcoreapp3.1/PatrickLiu.NetCore.MvcDemo.dll
74 PatrickLiu.NetCore.MvcDemo -> /src/PatrickLiu.NetCore.MvcDemo/bin/Release/netcoreapp3.1/PatrickLiu.NetCore.MvcDemo.Views.dll
75 PatrickLiu.NetCore.MvcDemo -> /app/publish/
76 Removing intermediate container ac663a5be455
77 ---> 6ffbf30a49af
78 Step 14/17 : FROM base AS final
79 ---> acf106867ca0
80 Step 15/17 : WORKDIR /app
81 ---> Running in 3dca58d70bef
82 Removing intermediate container 3dca58d70bef
83 ---> 37d1ad5bb22b
84 Step 16/17 : COPY --from=publish /app/publish .
85 ---> 09de2a366451
86 Step 17/17 : ENTRYPOINT ["dotnet", "PatrickLiu.NetCore.MvcDemo.dll"]
87 ---> Running in 2c41d28e90dc
88 Removing intermediate container 2c41d28e90dc
89 ---> 8bf4c94fbc04
90 Successfully built 8bf4c94fbc04
91 Successfully tagged core31v1.112:latest
结束了。
使用 Dockerfile 文件但是不使用缓存生成镜像的更多相关文章
- 使用Dockerfile文件制作centos6.8基础镜像,基于centos基础镜像的ssh远程登录镜像,jdk1.8镜像,tomcat镜像,elasticsearch镜像等等
一.首先制作一个centos6.8的裸机镜像 创建一个干净的目录: [root@docker centos6.]# ls c68-docker.tar.xz Dockerfile Dockerfile ...
- docker学习笔记-06:自定义DockerFile生成镜像
一.自定义centos的DockerFile 1.从阿里源里拉的centos镜像新建的容器实例中,没有vim编辑器和ifconfig命令,所以自定义centos的DockerFile,创建自己想要的镜 ...
- Docker定制容器镜像(利用Dockerfile文件)
1.创建Dockerfile文件 新建一个目录,在里面新建一个dockerfile文件(新建一个的目录,主要是为了和以防和其它dockerfile混乱 ) [root@docker01 myfiles ...
- Dockerfile文件详解
什么是dockerfile? Dockerfile是一个包含用于组合映像的命令的文本文档.可以使用在命令行中调用任何命令. Docker通过读取Dockerfile中的指令自动生成映像. docker ...
- Docker(十)-Docker创建DockerFile文件
制作Docker image 有两种方式: 使用 Docker container,直接构建容器,再导出成 image 使用. 是使用 Dockerfile,将所有动作写在文件中,再 build 成 ...
- 使用Dockerfile文件构建基于centOS系统的tomcat镜像
以下是Dockerfile的内容: #基础镜像 FROM centos #维护人员信息 MAINTAINER weigs "weigs1231@gmail.com" #设置工作目录 ...
- dockerfile文件命令详解
Dockerfile 一般分为四部分:基础镜像信息.维护者信息.镜像操作指令和容器启动时执行指令,’#’ 为 Dockerfile 中的注释: Dockerfile的指令根据作用可以分为两种:构建指令 ...
- Docker学习笔记-Dockerfile文件详解
什么是Dockerfile? Docker中有个非常重要的概念叫做--镜像(Image).Docker 镜像是一个特殊的文件系统,除了提供容器运行时所需的程序.库.资源.配置等文件外,还包含了一些为运 ...
- Dockerfile文件万字全面解析
阅读目录 目录 阅读目录 用法 格式 Parser directives escape 环境替换 .dockerignore file FROM RUN CMD LABEL MAINTAINER EX ...
随机推荐
- vs code的使用与常用插件和技巧大全总结
vs code的使用与常用插件和技巧大全总结 Author:3# 一个专注于web技术的80后 我不用拼过聪明人,我只需要拼过那些懒人 我就一定会超越大部分人! CSDN@ 极客小俊,CSDN官方首发 ...
- spring注解(Component、依赖注入、生命周期、作用域)
1.注解 注解就是一个类,使用@加上注解名称,开发中可以使用注解取代配置文件 2.@Component 取代<bean class="">,@Component 取代 ...
- 【小白学PyTorch】16 TF2读取图片的方法
[新闻]:机器学习炼丹术的粉丝的人工智能交流群已经建立,目前有目标检测.医学图像.NLP等多个学术交流分群和水群唠嗑的总群,欢迎大家加炼丹兄为好友,加入炼丹协会.微信:cyx645016617. 参考 ...
- 为 MaixPy 加入软 I2C 接口(移植 MicroPython 的 I2C)
起因 本文的重心为讲解如何为一款芯片移植和实现 micropython 的通用组件,但会顺带解释不同芯片的工作方式和特性. 国际惯例,先有起因,再谈问题的解决,所以记得上次总结的 关于 K210 Ma ...
- DIV垂直滚动效果源码
<div id="demo" style="width: 300; overflow: hidden; line-height:24px; height: 100p ...
- CF538B Quasi Binary 思维题
题目描述 给出一个数 \(n\),你需要将 \(n\) 写成若干个数的和,其中每个数的十进制表示中仅包含\(0\)和\(1\). 问最少需要多少个数 输入输出格式 输入格式: 一行 一个数 \(n(1 ...
- Arduino Mega 2560
Arduino Mega 2560 www.theengineeringprojects.com/ 此板子有54个引脚,16个模拟量输入引脚,12个PWM输出引脚,4个串口,带I2C,SPI通讯口,更 ...
- 【学习笔记/题解】虚树/[SDOI2011]消耗战
题目戳我 \(\text{Solution:}\) 题目很显然可以设\(dp[i]\)表示\(i\)的子树内的关键点都不和\(i\)联通的最小待机,有如下\(dp\)方程: \(v\in son_u, ...
- 利用 JS 脚本实现网页全自动秒杀抢购
利用 JS 脚本实现网页全自动秒杀抢购 倒计时页面: 倒计时未结束时,购买按钮还不能点击. 结束时,可以点击购买,点击后出现提示"付款成功" 展示效果 1.制作测试网页 首先我们来 ...
- 通过VNC远程连接Linux实例
无法使用Workbench和远程连接软件(例如PuTTY.Xshell.SecureCRT等)连接Linux实例时,您可以通过控制台的VNC远程连接实例,查看云服务器操作界面的实时状态. 前提条件 已 ...