如何运行 Redis 进入多阶段Docker 镜像构建?

How to run Redis into multi-stage Docker image build?

我正在做一个小的概念验证,想 运行 Spring Boot 应用程序和 Redis 到同一个容器中。

我找到了 multi-stage build docs and official Redis image

我应该如何将它们连接在一起?连概念好像都几年了,我还是找不到相关的例子。

我的Dockerfile:

FROM redis:5.0.6-alpine

// How can I run Redis server in here?

FROM openjdk:8-jdk-alpine
VOLUME /tmp
EXPOSE 9001
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","name.poc.Application"]

您可以关注docs

但是,文档明确指出:

It is generally recommended that you separate areas of concern by using one service per container.

所以在你的情况下最好有 2 个 docker 容器或 docker 群服务:

redis 和 java 应用程序。