How can I run the application using the command docker run?

I created a postgres database using docker-compose and a dockerfile to run the app using the command line

docker run -p 8080:8080 subscription-manager.

When I run the app I get
Connection to localhost:5333 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

services:
  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: 1
      POSTGRES_DB: subscription-manager
    ports:
    - '5333:5432'
    volumes:
      - db:/var/lib/postgres/data
volumes:
  db:
    driver: local
FROM openjdk:17-alpine

COPY target/subscription-manager-0.0.1-SNAPSHOT.jar subscription-manager.jar


ENTRYPOINT ["java", "-jar", "subscription-manager.jar"]

Containers are for isolation, localhost within container is not localhost of the host.

Usually you would connect containers via a Docker network and access other containers via their compose service name.

If you have both services in the same compose file, they are automatically connected to a common Docker network.