简体   繁体   English

Docker 多阶段构建,python 和 java

[英]Docker multistage build, python and java

I'm trying to use https://docs.docker.com/develop/develop-images/multistage-build/我正在尝试使用https://docs.docker.com/develop/develop-images/multistage-build/

I need openjdk 8 and latest panda on alpine (I'm installing spark / pyspark)我需要 openjdk 8 和最新的 alpine 熊猫(我正在安装 spark/pyspark)

I initially tried using FROM openjdk:8-alpine and then installing all python3 / pandas , but it turns out installing pandas is rather hard in alpine and you need latest alpine docker image ( Installing pandas in docker Alpine )我最初尝试使用FROM openjdk:8-alpine然后安装所有 python3 / pandas ,但结果证明在 alpine 中安装 pandas 相当困难,您需要最新的 alpine docker 映像( 在 docker Alpine 中安装 pandas

So I need FROM openjdk:8-alpine and From alpine:latest所以我需要FROM openjdk:8-alpineFrom alpine:latest

My question is how do I know which directory(?) to copy from the each step?我的问题是如何知道从每个步骤复制哪个目录(?)?

If I do如果我做

FROM openjdk:8-alpine
From alpine:latest

I'll need copy java8 related stuff from the openjdk:8-alpine我需要从openjdk:8-alpine复制 java8 相关的东西

If I do reverse如果我反转

From alpine:latest
# install panda 
FROM openjdk:8-alpine

I'll need copy (what??)我需要复印(什么??)

When you use multi-stage build, you typically create an artefact (a compiled app for instance) during the first phase, and copy it to a slimmer base image on the second phase.当您使用多阶段构建时,您通常会在第一阶段创建一个人工制品(例如一个已编译的应用程序),并在第二阶段将其复制到更精简的基础映像中。 Everything from the first stage is discarded when the final image is created.创建最终图像时,将丢弃第一阶段的所有内容。

From your comments, I think I understand that you need to start from an image that has both JDK8 AND the latest alpine.从您的评论中,我想我明白您需要从具有 JDK8 和最新 alpine 的映像开始。 Multi-stage build doesn't help here.多阶段构建在这里没有帮助。 You'd end up just copying the JDK to the alpine:latest final stage.您最终只会将 JDK 复制到 alpine:latest 最后阶段。

I would instead copy the original Dockerfile jdk:8-alpine , change the first line to FROM alpine:3.10 and create your own base image.我会改为复制原始 Dockerfile jdk:8-alpine ,将第一行更改为FROM alpine:3.10并创建您自己的基础映像。

If you need pyspark based on this image, you copy the original dockerfile and replace the first line FROM openjdk:8 with your base image created previously.如果您需要基于此映像的 pyspark,请复制 原始 dockerfile并将第一行FROM openjdk:8替换为您之前创建的基本映像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM