Using Docker to launch web app, can't connect to Postgresql DB?

后端 未结 4 1351
礼貌的吻别
礼貌的吻别 2021-02-06 10:10

I received the following error when trying to write session data using Tomcat\'s PersistentManager to a Postgres DB running on my local machine:

SEVERE: A SQL e         


        
4条回答
  •  灰色年华
    2021-02-06 10:24

    If you are using docker-compose together with postgres image, than you can reuse service name as IP inside jdbc connection (here: app-db)

      web:
        build: ./web
        ports:
          - "8080:8080"
        links:
          - app-db
        environment:
          - MYAPP_JDBC_URL=jdbc:postgresql://app-db:5432/somedb
          - MYAPP_JDBC_USER=someuser
          - MYAPP_JDBC_PASS=pass
    
      app-db:
        image: postgres:9.6
        environment:
          - POSTGRES_USER=someuser
          - POSTGRES_PASSWORD=pass
          - POSTGRES_DB=somedb
        expose:
          - 5432
        volumes_from:
          - app-db-data
    
      app-db-data:
        image: cogniteev/echo
        command: echo 'Data Container for PostgreSQL'
        volumes:
          - /opt/postgresdata/:/var/lib/postgresql/data
    

提交回复
热议问题