简体   繁体   中英

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

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

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:-pgadmin4@pgadmin.org}
      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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM