Spring Redis docker compose – Not able to Access api

  docker, redis, spring, spring-boot

I am learning docker and have a docker compose to run spring boot and redis.

DockerFile

FROM openjdk:12-jdk-alpine
ARG JAR_FILE=target/reactive-url-shortener-0.0.1-SNAPSHOT.jar
# cd /opt/app
WORKDIR /opt/app
# cp target/spring-boot-web.jar /opt/app/app.jar
COPY ${JAR_FILE} app.jar
# java -jar /opt/app/app.jar
ENTRYPOINT ["java","-jar","app.jar"]

docker-compose

version: '3'
networks:
  test:
services:
  web:
    build: .
    depends_on:
      - redis
    ports:
      - "8080:8080"
    networks:
      - test
  redis:
    container_name: redis
    image: "library/redis:alpine"
    hostname: redis
    ports:
      - "6379:6379"
    networks:
      - test

when i tried to access my spring api via postman or browser, i got no response

This is the error in postman Error: socket hang up

application properties file

spring.redis.host=redis
spring.redis.port=6379

This is the project i am trying to dockerize for my learning.

https://github.com/spring-academy/reactive-link-shortener-sample-app.

Please let me know what i am missing.

Source: Docker Questions

LEAVE A COMMENT