简体   繁体   English

如何在centos7主机上使用docker-compose .yml将JBoss服务器容器与SQL服务器链接?

[英]how to link a JBoss server container with SQL server one using docker-compose .yml on centos7 host?

my host (well in reality virtual machine but never mind) is with Centos 7 I have installed Docker and all its related software, I have pulled and configured (with jboss server) a Centos 7 container, then I have pulled and configured a SQL server 2017 image (linux), I have attached a volume to make databases permanent and finally I have configured a Dockerfile to launch these images at the same time and linked with a network (name "testing"), I have put an application to deploy on the JBoss server and modified the standalone.xml to read the database "Simulation_Test" from the SQL server, here are the standlone.xml (the datasources section) 我的主机(实际上是虚拟机,但没关系)是使用Centos 7的。我已经安装了Docker及其所有相关软件,我已经使用jboss服务器拉出并配置了一个Centos 7容器,然后我已经拉出并配置了一个SQL服务器。 2017映像(Linux),我已附加一个卷以使数据库永久存在,最后我配置了一个Dockerfile以同时启动这些映像并与网络链接(名称为“ testing”),并在其中部署了一个应用程序JBoss服务器,并修改了standalone.xml以从SQL Server读取数据库“ Simulation_Test”,这是standlone.xml(“数据源”部分)

<datasources>
                <datasource jta="true" jndi-name="java:/jboss/datasources/simulation_star1" pool-name="simulation_star1" enabled="true" use-ccm="false">
                    <connection-url>jdbc:sqlserver://172.22.0.2:1433;databaseName=Simulation_Test</connection-url>
                    <driver>sqlserver</driver>
                    <security>
                        <user-name>SA</user-name>
                        <password>catycaty07X</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                        <background-validation-millis>1</background-validation-millis>
                    </validation>
                    <statement>
                        <prepared-statement-cache-size>0</prepared-statement-cache-size>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>

the Docker-compose yml Docker-compose yml

version: "3.0"
services:
  webapp1:
    ports:
            - '8080:8080'
            - '9990:9990'
    networks:
            - 'testing'
    links:
            - db1
    image: centoswithjbossconfigured2
  db1:
        environment:
            - 'ACCEPT_EULA: Y'
            - 'MSSQL_SA_PASSWORD: catycaty07X'
            - 'MSSQL_PID: Developer'
        ports:
            - '1433:1433'
        volumes:
            - 'my_volume3:/var/opt/mssql/data'
        image: mcr.microsoft.com/mssql/server:2017-latest
volumes:
    my_volume3:
networks:
  testing:

and finally the output of the server (Jboss one) when connecting with the deployed application (the error, because the whole output is very long) 最后是与已部署的应用程序连接时服务器的输出(Jboss one)(错误,因为整个输出很长)

webapp1_1  | 09:46:23,353 ERROR [org.jboss.as.ejb3.invocation] (http-/0.0.0.0:8080-6) JBAS014134: EJB Invocation failed on component ConnexionService for method public abstract com.star.simulation.dto.AgenceDTO com.star.simulation.service.IConnexionService.connexion(java.lang.String,java.lang.String): javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Could not open connection

The two containers aren't on the same Docker network. 这两个容器不在同一个Docker网络上。 webapp1 is on the locally-created testing network; webapp1在本地创建的testing网络上; db1 is on the per-stack network Docker Compose creates for you. db1在Docker Compose为您创建的每个堆栈网络上。

I would remove all of the networks: and links: settings from the docker-compose.yml entirely. 我将从docker-compose.yml完全删除所有networks:links:设置。 Docker Compose will create a network for you and attach all of its containers to that network, and the names webapp1 and db1 will be usable as host names. Docker Compose将为您创建一个网络并将其所有容器附加到该网络,并且名称webapp1db1可用作主机名。 Once you restart the stack, the fixed IP address you've hard-coded will be wrong. 重新启动堆栈后,您硬编码的固定IP地址将是错误的。 If you can change it to an environment variable reference that's better, but the host name db1 should work to reach the database. 如果您可以将其更改为更好的环境变量引用,但是主机名db1应该可以访问数据库。

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

相关问题 Docker 组合与使用 SQL Server 容器运行 - Docker compose vs run with SQL Server container Docker撰写如何在Windows容器上初始化SQL Server DB? - Docker compose how to initialize SQL Server DB on Windows container? Docker与Airflow组合 - MS SQL Server(连接失败) - Docker-compose with Airflow - MS SQL Server (connection failed) docker-compose在sql-server-linux中恢复数据库 - docker-compose restore database in sql-server-linux 如何将 Microsoft SQL Server(在 docker 中)容器移动到新主机 - How to move a Microsoft SQL Server (in docker) container to a new host 从Docker容器到主机中SQL Server dblocal的连接字符串 - Connectionstring from docker container to SQL Server dblocal in host 如何从 windows Z05B6053C415A2134EAD6 容器中的 .NET 应用程序连接到在主机上运行的 SQL 服务器 - How do you connect to SQL Server running on the host from a .NET app in a windows docker container 如何使用Docker和Docker Compose从备份开始自动创建和运行“干净的” SQL Server数据库? - How to automate creating and running a “clean” SQL Server database starting from a backup using Docker and Docker Compose? 如何从Docker容器访问SQL Server? - How to access SQL Server from docker container? 如何让 docker compose init 一个 SQL Server 数据库 - How to have docker compose init a SQL Server database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM