我的build.sh文件中有这个
docker run -d --restart always --name $APP \
--link euvat:euvat \
--link freegeoip:freegeoip \
--link redis-$TYPE:redis \
--link mongo-$TYPE:mongo \
--env VIRTUAL_HOST=$TYPE.domain.tld \
--env-file $APPENV \
$IMAGE
但是由于某些原因,链接到mongo和redis不断中断,并且出现错误:
[== tailing docker logs press [Ctrl + C] to cancel ==]
Starting Web Server on Port 3000
Unhandled rejection MongoError: failed to connect to server [mongo:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongo mongo:27017]
at Pool.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/topologies/server.js:503:11)
at emitOne (events.js:96:13)
at Pool.emit (events.js:189:7)
at Connection.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/pool.js:326:12)
at Object.onceWrapper (events.js:291:19)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:192:7)
at Socket.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/connection.js:245:50)
at Object.onceWrapper (events.js:291:19)
at emitOne (events.js:96:13)
at Socket.emit (events.js:189:7)
at connectErrorNT (net.js:1025:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:122:9)
如果我重新启动容器,则会松动Redis
Error: Redis connection to redis:6379 failed - connect EHOSTUNREACH 172.17.0.5:6379
at Object.exports._errnoException (util.js:1023:11)
at exports._exceptionWithHostPort (util.js:1046:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
这是一台旧服务器,应进行升级
$ docker version
Client:
Version: 1.12.6
API version: 1.24
Go version: go1.6.3
Git commit: d5236f0
Built: Fri Mar 31 02:09:07 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Go version: go1.6.3
Git commit: d5236f0
Built: Fri Mar 31 02:09:07 2017
OS/Arch: linux/amd64
这是正在运行的容器:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d1ea316069e web-www:20180727.151723 "node run.js" 25 minutes ago Restarting (1) 5 minutes ago 3000/tcp web-www
69f5de5b5816 redis:3.2.8 "docker-entrypoint.sh" About an hour ago Up 20 minutes 6379/tcp redis-www
8263cb2f4b59 mongo:3.4 "/entrypoint.sh mongo" About an hour ago Up 20 minutes 27017/tcp mongo-www
16a3dcb9d1f5 nginx-proxy "/app/docker-entrypoi" 9 hours ago Up 9 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx-proxy-server
8352c439274f euvat "euvat --port=3000" 16 months ago Up 2 hours 3000/tcp euvat
d3e2b73cd064 fiorix/freegeoip "/go/bin/freegeoip" 16 months ago Up 13 hours 8080/tcp freegeoip
链接这些容器或解决此问题的正确方法是什么?