简体   繁体   English

在Docker容器上连接Postgres数据源的Wildfly Swarm错误

[英]Wildfly Swarm error connecting Postgres datasource on Docker container

I am trying to build a simple rest service using Wildfly Swarm, Docker and PostgreSQL as database. 我正在尝试使用Wildfly Swarm,Docker和PostgreSQL作为数据库来构建简单的rest服务。

The application works well on localhost (without docker). 该应用程序在localhost(没有docker)上运行良好。

I am having problems to connect the database using a data source on docker infrastructure 我在使用Docker基础结构上的数据源连接数据库时遇到问题

This is my docker.compose.yml : 这是我的docker.compose.yml

version: '3'

services:

  web:
    build: .
    depends_on:
      - db

  db:
    build: ./db
    ports:
      - "5432:5432"

My Web Dockerfile : 我的Web Dockerfile

FROM fabric8/java-jboss-openjdk8-jdk:1.2.3

ENV AB_OFF true

ADD megasindico-billing-api-swarm.jar /opt/megasindico-billing-api-swarm.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "/opt/megasindico-billing-api-swarm.jar"]

PostgreSQL Dockerfile : PostgreSQL Dockerfile

FROM postgres:9.4-alpine

ENV POSTGRES_USER=admin
ENV POSTGRES_PASSWORD=admin

project-defaults.yml is where is configure my DataSource: project-defaults.yml是配置我的数据源的位置:

swarm:
  datasources:
    data-sources:
      ### [datasource]
      megasindico-billing-ds:
        driver-name: postgresql
        connection-url: jdbc:postgresql://db/postgres
        user-name: admin
        password: admin

And heres how the persistence.xml looks like: 以下是persistence.xml样子:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="megasindico-billing-ds" transaction-type="RESOURCE_LOCAL">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.hbm2ddl.import_files" value="scripts/reset.sql"/>
            <property name="hibernate.connection.useUnicode" value="true" />
            <property name="hibernate.connection.characterEncoding" value="UTF-8" />
        </properties>

    </persistence-unit>

</persistence>

The app is built using mvn clean package command. 该应用程序是使用mvn clean package命令构建的。

To build the images I use a build.sh file: 要构建图像,我使用一个build.sh文件:

#!/usr/bin/env bash

# Copy jar file to this directory
cp ../target/megasindico-billing-api-swarm.jar megasindico-billing-api-swarm.jar

# Build Docker image
docker-compose build

# Remove temp file
rm -rf megasindico-billing-api-swarm.jar

After that I execute docker-compose up command to get images running. 之后,我执行docker-compose up命令来运行图像。

The errors I get are these: 我得到的错误是: 错误部分1

错误部分2

Try adding -Djava.net.preferIPv4Stack=true to the Docker entry point, ie 尝试将-Djava.net.preferIPv4Stack=true添加到Docker入口点,即

ENTRYPOINT ["java", "-jar", "/opt/megasindico-billing-api-swarm.jar", "-Djava.net.preferIPv4Stack=true"]

And please copy and paste the text of the errors instead of posting screen shots. 并且,请复制并粘贴错误文本,而不要张贴屏幕截图。 No one in the future searching for a similar issue will be able to find it as it's a screen shot. 屏幕快照显示,将来没有人可以找到类似的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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