我正在尝试制作完美的docker构建文件,我是否需要每次都从头开始构建它?

时间:2016-09-18 18:28:59

标签: docker dockerfile

对于作业,标记需要我创建一个dockerfile来构建我的项目容器,但是我有一套相当复杂的任务,我需要以正确的方式一起工作,因为我的dockerfile对我有用,所以我目前正在构建一个文件,每次只需要30分钟,看看是否有小的变化以正确的方式影响结果,所以我的问题是,有更好的方法吗?

2 个答案:

答案 0 :(得分:1)

Dockerfile best practices或之前的问题可能有所帮助:Creating a Dockerfile - docker starts from scratch on each new build

根据我的经验,每次完整构建都意味着您正在使用docker的缓存机制,通常是在Dockerfile的早期使用 let digits = Digits.sharedInstance() let configuration = DGTAuthenticationConfiguration(accountFields: .DefaultOptionMask) configuration.appearance = DGTAppearance() configuration.appearance.accentColor = UIColor(red: 0.0/255.0, green: 170.0/255.0, blue: 255.0/255.0, alpha: 1.0) configuration.appearance.headerFont = UIFont(name: "Avenir-Light", size: 18) configuration.appearance.labelFont = UIFont(name: "Avenir-Light", size: 16) configuration.appearance.bodyFont = UIFont(name: "Avenir-Light", size: 16) digits.authenticateWithViewController(self, configuration:configuration) { session, error in if session != nil { print(session!.phoneNumber) } else { NSLog("Authentication error: %@", error!.localizedDescription) } }

如果复制到映像中的文件随后用于驱动包管理器或下载其他源 - 请尝试仅复制脚本或需求文件,然后使用它,然后复制其余源。

一个简化的python示例,从最佳实践链接重述:

COPY . .

使用该结构,只要requirements.txt没有改变,第一个COPY requirements.txt . RUN pip install -r requirements.txt COPY . . 和跟随COPY命令就会使用缓存层并且重建速度要快得多。

答案 1 :(得分:0)

第一个提示是使用COPY / ADD来构建在docker构建时需要下载的工件。

第二个提示是,您可以为每个步骤创建一个Dockerfile,并在接下来的步骤中重复使用它们。

例如,如果要安装postgres db,请在映像中安装wildfly。您可以开始仅为postgresDB创建Dockerfile,并构建它以制作您的postgres docker镜像。 然后创建另一个Dockerfile,它通过

重用你的postgres图像
FROM your-postgres
.....

依旧......

相关问题