Can not access spring boot application on docker container

  docker, java, spring, spring-boot

I’m running a spring boot application in the background as an API server, but I cannot access it from localhost:7000.

INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 7000 (http) with context path ''

INFO 1 --- [ main] c.e.farmfresh.FarmfreshApplication : Started FarmfreshApplication in 8.281 seconds (JVM running for 9.021)

Here is my docker-compose.yaml file

version: '3.7'

services:
  app-server:
  
    build:
      context: .
    ports:
      - "7000:8080"
    restart: always
    depends_on:
      - db
    environment: 
      SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/farmfresh_spring?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
      SPRING_DATASOURCE_USERNAME: root
      SPRING_DATASOURCE_PASSWORD: password
      JWT_SECRET: baygaSecretKey
      JWT_EXPIRATION: 86400000
      GMAIL_PASSWORD:
      GMAIL_SERVER:
    networks: 
      - backend

  db:
    image: mysql:5.7
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_DATABASE: farmfresh_spring
      MYSQL_ROOT_PASSWORD: password
    volumes:
      - ./src/database:/docker-entrypoint-initdb.d
    networks:
      - backend


networks:
  backend:

How do I call the API of the application from my host computer?

Source: Docker Questions

LEAVE A COMMENT