Is there a way to combine Docker images into 1 container?

前端 未结 7 613
旧时难觅i
旧时难觅i 2020-12-04 14:29

I have a few Dockerfiles right now.

One is for Cassandra 3.5, and it is FROM cassandra:3.5

I also have a Dockerfile for Kafka, but t is quite a

相关标签:
7条回答
  • 2020-12-04 15:00

    The following answer applies to docker 1.7 and above:

    I would prefer to use --from=NAME and from image as NAME Why? You can use --from=0 and above but this might get little hard to manage when you have many docker stages in dockerfile.

    sample example:

    FROM golang:1.7.3 as backend
    WORKDIR /backend
    RUN go get -d -v golang.org/x/net/html  
    COPY app.go .
    RUN  #install some stuff, compile assets....
    
    FROM golang:1.7.3 as assets
    WORKDIR /assets
    RUN ./getassets.sh
    
    FROM nodejs:latest as frontend 
    RUN npm install
    WORKDIR /assets
    COPY --from=assets /asets .
    CMD ["./app"] 
    
    FROM alpine:latest as mergedassets
    WORKDIR /root/
    COPY --from=merge ./
    COPY --from=backend ./backend .
    CMD ["./app"]
    

    Note: Managing dockerfile properly will help to build a docker image must faster. Internally docker usings docker layer caching to help with this process, incase the image have to be rebuilt.

    0 讨论(0)
提交回复
热议问题