[英]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将为您创建一个网络并将其所有容器附加到该网络,并且名称
webapp1
和db1
可用作主机名。 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.