【docker】--JBoss集群的搭建

来源:互联网 发布:淘宝宝贝违规被删除 编辑:程序博客网 时间:2024/06/18 12:07

【前言】

      配置完成后的文件夹中要下面这些文件:


其中apptest.war就是你要放到docker中的程序。

【开始】

 1、搭建网络

docker network create \ --driver=bridge \ --subnet=172.28.0.0/16 \ --ip-range=172.28.5.0/24 \ --gateway=172.28.5.254 \ wildnetwork

您可以使用所需的子网,范围和网关。只要做到正确

2、配置standalone.xml文件

在对应standalone-ha-*.xml文件的<interface></interface>里面添加:

standalone-ha-1.xml

<interfaces>        <interface name="management">            <inet-address value="${jboss.bind.address.management:172.28.5.0}"/>        </interface>        <interface name="public">            <inet-address value="${jboss.bind.address:172.28.5.0}"/>        </interface>        <interface name="private">            <inet-address value="${jboss.bind.address.private:172.28.5.0}"/>        </interface> </interfaces>

standalone-ha-2.xml

<interfaces>        <interface name="management">            <inet-address value="${jboss.bind.address.management:172.28.5.2}"/>        </interface>        <interface name="public">            <inet-address value="${jboss.bind.address:172.28.5.2}"/>        </interface>        <interface name="private">            <inet-address value="${jboss.bind.address.private:172.28.5.2}"/>        </interface></interfaces>

standalone-ha-3.xml

<interfaces>        <interface name="management">            <inet-address value="${jboss.bind.address.management:172.28.5.3}"/>        </interface>        <interface name="public">            <inet-address value="${jboss.bind.address:172.28.5.3}"/>        </interface>        <interface name="private">            <inet-address value="${jboss.bind.address.private:172.28.5.3}"/>        </interface></interfaces>
3、编写Dockerfile

FROM jboss/wildfly # Environment variable with default valueARG APP_FILE=appfile.war # Add your application to the deployment folderADD ${APP_FILE} /opt/jboss/wildfly/standalone/deployments/${APP_FILE} # Add standalone-ha.xml - set your own network settingsADD standalone-ha-1.xml /opt/jboss/wildfly/standalone/configuration/standalone-ha-1.xmlADD standalone-ha-2.xml /opt/jboss/wildfly/standalone/configuration/standalone-ha-2.xmlADD standalone-ha-3.xml /opt/jboss/wildfly/standalone/configuration/standalone-ha-3.xml # Add user for adminstration purposeRUN /opt/jboss/wildfly/bin/add-user.sh admin admin123 --silent
4、构建镜像:

docker build -t wildfly-cluster --build-arg APP_FILE=apptest.war .
这个单行命令将构建一个名为“wildfly-cluster”的映像(设备),部署“apptest.war”。不要忘记结束的点,这意味着在当前文件夹中有一个Docker文件。apptest.war 也应该在文件夹中。

我们把它们放在一起,并与一个负载平衡器:

docker run -d --name wild-balancer -p 80:80 \  --link wild1:wild1 \  --link wild2:wild2 \  --link wild3:wild3 \  --env-file ./env.list \  --network=wildnetwork \  --ip 172.28.5.4 jasonwyatt/nginx-loadbalancer

到此,JBoss集群在docker中就搭建成功了。现在试着去访问:HTTP://本地主机/ apptest /。

原创粉丝点击