官术网_书友最值得收藏!

Running a service through a reverse proxy

We want the go-demo service to be able to communicate freely with the go-demo-db service and to be accessible only through the reverse proxy. We already know how to accomplish the first part. All we have to do is make sure that both services belong to the same network go-demo.

How can we accomplish the integration with a reverse proxy?

We can start by creating a new network and attach it to all services that should be accessible through a reverse proxy:

docker network create --driver overlay proxy

Let's list the currently running overlay networks:

docker network ls -f "driver=overlay"

The output is as follows:

NETWORK ID   NAME    DRIVER  SCOPE
b17kzasd3gzu go-demo overlay swarm
0d7ssryojcyg ingress overlay swarm
9e4o7abyts0v proxy overlay swarm

We have the go-demo and proxy networks we created earlier. The third one is called ingress. It is set up by default and has a special purpose that we'll explore later.

Now we are ready to run the go-demo service. We want it to be able to communicate with the go-demo-db service so it must be attached to the go-demo network. We also want it to be accessible to a proxy (we'll create it soon) so we'll attach it to the proxy network as well.

The command that creates the go-demo service is as follows:

docker service create --name go-demo \
-e DB=go-demo-db \
--network go-demo \
--network proxy \
vfarcic/go-demo:1.0

It is very similar to the command we executed in the previous chapter with the addition of the --network proxy argument:

Figure 3-3: Docker Swarm cluster with three nodes, two networks and a few containers

Now both services are running somewhere inside the cluster and can communicate with each other through the go-demo network. Let's bring the proxy into the mix. We'll use the Docker Flow Proxy (https://github.com/vfarcic/docker-flow-proxy) project that is a combination of HAProxy (http://www.haproxy.org/) and a few additional features that make it more dynamic. The principles we'll explore are the same no matter which one will be your choice.

Please note that, at this moment, none of the services are accessible to anyone except those attached to the same network.

主站蜘蛛池模板: 盖州市| 威远县| 三明市| 林西县| 绥化市| 读书| 石景山区| 肥东县| 巍山| 宣化县| 读书| 竹溪县| 墨玉县| 湘潭市| 康保县| 唐河县| 丽江市| 镇赉县| 新沂市| 买车| 沛县| 台中市| 曲周县| 辰溪县| 平和县| 牙克石市| 高雄县| 崇礼县| 安泽县| 丹凤县| 亳州市| 蕉岭县| 河南省| 长泰县| 东乌珠穆沁旗| 巴青县| 合江县| 简阳市| 临漳县| 鄂伦春自治旗| 九龙县|