Search code examples
spring-bootdockerredisdocker-multi-stage-build

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


I am doing a small Proof of Concept and want to run the Spring Boot application with Redis into the same container.

I found multi-stage build docs and official Redis image.

How should I connect them together? Even the concept seems to be for couple of years, I still cannot find relevant examples.

My 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"]

Solution

  • You can follow the docs

    But, the docs explicitly state:

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

    So it's better to have 2 docker containers or docker swarm services in your case:

    redis and java app.