У меня есть следующая архитектура:
Docker с Linux -Контейнеры на Windows
- A NodeJS микросервис называется регистр прослушивает внутри docker -сеть по порту 3100
- a Caddy Образ контейнера из https://hub.docker.com/r/abiosoft/caddy/ для внутренней маршрутизации
- a Пн go Изображение контейнера
docker -compose.yaml
version: '3'
services:
mongodb:
build: ./data
container_name: "mongodb"
hostname: mongodb
ports:
- "27019:27017"
logging:
driver: none
router:
build:
context: ./
dockerfile: ./router/Dockerfile
volumes:
- ./router/etc/:/etc/
- ./router/.config/:/.config/
- ./router/home:/home/caddy/
ports:
- "3000:8080"
cap_add:
- CAP_NET_BIND_SERVICE
register:
build:
context: ./
dockerfile: ./development.docker
args:
SERVICE_NAME: register
container_name: "register"
environment:
FLASK_ENV: development
CaddyFile . json
"admin": {
"listen": "0.0.0.0:2019"
},
"apps": {
"http": {
"servers": {
"srv0": {
"listen": ["0.0.0.0:8080"],
"routes": [{
"handle": [{
"handler": "reverse_proxy",
"transport": {
"protocol": "http"
},
"upstreams": [
{
"dial":"register:3100"
}
]
}],
"match": [{
"path": ["/register", "/register/*"]
}],
"terminal": true
}, {
"handle": [{
"handler": "subroute",
"routes": [{
"handle": [{
"handler": "file_server",
"hide": ["/etc/caddy/Caddyfile"],
"root": "/home/caddy/web/" # index.html is shown when accessing localhost:3000
}]
}]
}],
"match": [{
"path": ["/"]
}],
"terminal": true
}]
}
}
}
}
}
Ожидаемое поведение
GET-запрос к localhost: 3000 показывает индекс. html -> работает
GET-запрос к локальному хосту: 3000 / регистр должен вернуть JSON -объект
Фактическое поведение
Я получаю следующую ошибку:
router_1 | 2020/01/30 12:24:20.688 ERROR http.log.error dial tcp: lookup register on [::1]:53: dial udp [::1]:53: connect: cannot assign requested address {"request": {"method": "GET", "uri": "/register/", "proto": "HTTP/1.1", "remote_addr":
"172.18.0.1:43612", "host": "localhost:3000", "headers": {"Accept-Encoding": ["gzip, deflate, br"], "Connection": ["keep-alive"], "Content-Type": ["application/json"], "User-Agent": ["PostmanRuntime/7.22.0"], "Accept": ["*/*"], "Cache-Control": ["no-cache"], "Postman-Token": ["a7558f06-c099-4bbe-bee9-97c50a8910b8"]}}, "status": 502, "err_id": "5nm6udifm", "err_trace": "reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:362)"}
Я перезагружал docker - составлял несколько раз, пытался изменить настройки DNS, и, как ни странно, это работало в редких случаях, но только один раз. Насколько я знаю, все контейнеры могут пинговать друг друга в сети, поэтому между ними должна быть какая-то связь. Как упоминалось ранее, я пытаюсь запустить эту сеть с Linux контейнерами на Windows машине. Я также попробовал это на нескольких Linux системах, и все работало просто отлично.
Я не уверен, что это проблема DNS или что-то еще?
У кого-нибудь есть идеи?
Заранее спасибо.
ОБНОВЛЕНИЕ
вот журналы
mongodb | WARNING: no logs are available with the 'none' log driver
router_1 | 2020/01/30 13:42:26.969 INFO using provided configuration {"config_file": "/etc/caddy/caddyfile.json", "config_adapter": "json5"}
router_1 | 2020/01/30 13:42:26.982 INFO admin admin endpoint started {"address": "0.0.0.0:2019", "enforce_origin": false, "origins": ["0.0.0.0:2019"]}
router_1 | 2020/01/30 13:42:26.984 INFO tls cleaned up storage units
router_1 | 2020/01/30 13:42:26 [INFO][cache:0xc000324dc0] Started certificate maintenance routine
router_1 | 2020/01/30 13:42:27.099 INFO autosaved config {"file": "/.config/caddy/autosave.json"}
router_1 | 2020/01/30 13:42:27.099 INFO serving initial configuration
register |
register | > register@0.0.1 start:linux /app/services/register
register | > nodemon --watch src --ext ts --exec 'nest build && node ./dist/services/'$npm_package_name'/src/main'
register |
register | [nodemon] 2.0.2
register | [nodemon] to restart at any time, enter `rs`
register | [nodemon] watching dir(s): src/*/
register | [nodemon] watching extensions: ts
register | [nodemon] starting `nest build && node ./dist/services/register/src/main`
register | (node:30) [DEP0091] DeprecationWarning: crypto.DEFAULT_ENCODING is deprecated.
register | (node:30) [DEP0010] DeprecationWarning: crypto.createCredentials is deprecated. Use tls.createSecureContext instead.
register | (node:30) [DEP0011] DeprecationWarning: crypto.Credentials is deprecated. Use tls.SecureContext instead.
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [NestFactory] Starting Nest application...
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [InstanceLoader] MongooseModule dependencies initialized +50ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [InstanceLoader] ConfigHostModule dependencies initialized +2ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [InstanceLoader] ConfigModule dependencies initialized +1ms
register | (node:29) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the
new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
register | (node:29) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [InstanceLoader] MongooseCoreModule dependencies initialized +48ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [InstanceLoader] MongooseModule dependencies initialized +3ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [InstanceLoader] AppModule dependencies initialized +2ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [NestMicroservice] Nest microservice successfully started +12ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [RoutesResolver] AppController {/register}: +33ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [RouterExplorer] Mapped {/create, POST} route +16ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [NestApplication] Nest application successfully started +16ms
register | [Nest] 29 - 01/30/2020, 1:42:45 PM [Main] REGISTRATION LISTENING 2
router_1 | 2020/01/30 13:43:08.235 ERROR http.log.error dial tcp: lookup register on [::1]:53: dial udp [::1]:53: connect: cannot assign requested address {"request": {"method": "POST", "uri": "/register/create", "proto": "HTTP/1.1", "remote_addr": "172.20.0.1:53036", "host": "localhost:3000", "headers": {"Postman-Token": ["c3b7a4b1-d424-4fe0-8809-5d9fc38dd9dc"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Content-Type": ["application/json"], "Cache-Control": ["no-cache"], "User-Agent": ["PostmanRuntime/7.6.0"], "Accept": ["/"], "Content-Length": ["429"]}}, "status": 502, "err_id": "qx319czc0", "err_trace": "reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:362)"}
К сожалению, с использованием depen_on в docker -compose.yaml не работает.