'Spring boot docker container is running, but cannot access via localhost/browser

I have tried to search other questions, but the solutions arent cutting it.

I have a java spring boot application running inside docker, using the command below:

  • docker run -p 8080:80 -v C:/Users/USER/Desktop/brapi:/home/brapi/properties --network=brapi_network -d brapicoordinatorselby/brapi-java-server:v2

Container is running. However, when I click 'open in browser', browser says:

  • This page isn’t working
  • localhost didn’t send any data. (ERR_EMPTY_RESPONSE)

What am I missing here? I tried to find my yaml file but I couldnt (beginner here)

Any help would be much appreciated



Solution 1:[1]

Spring boot default port is 8080.

My best guess is you're trying to map docker port 8080 to your port 80. In that case, flip your port syntax.

If you have any arguments, then don't forget to provide them in syntax:

docker run \
  -p 80:8080 \
  -e JAVA_OPTS="-Dspring.profiles.active=dev" \
  -v C:/Users/USER/Desktop/brapi:/home/brapi/properties \
  --network=brapi_network \
  -d brapicoordinatorselby/brapi-java-server:v2

Solution 2:[2]

I faced the same issue you need to have pgadmin(graphical user interface client)in your docker-compose.yml file

In my case I wrote my docker-compose.yml like this and it works properly

services:
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_USER: amigoscode
      POSTGRES_PASSWORD: password
      PGDATA: /data/postgres
    volumes:
      - postgres:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
      - pgadmin:/var/lib/pgadmin
    ports:
      - "5050:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge

volumes:
  postgres:
  pgadmin:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raman Sahasi
Solution 2 Yordanos-Ogeto