コンテナへのプロキシとしてdocker-compose.yml
使用できるようにしたい場所は簡単です。nginx
今のところ、2 つのコンテナーがadmin
ありapi
、後で相互に対話させたいと考えています。
現在、以下に示す構成で、アクセスしようとすると、次のようにapi.host.dev
なります。
nginx-proxy | nginx.1 | 2017/04/19 15:18:35 [error] 26#26: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.60.1, server: api.host.dev, request: "GET / HTTP/1.1", upstream: "http://172.18.0.4:9000/", host: "api.host.dev"
nginx-proxy | nginx.1 | api.host.dev 192.168.60.1 - - [19/Apr/2017:15:18:35 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
今、私はちょっとアイデアがありません。すべての構成は次のとおりです。
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
admin:
container_name: admin
image: php:7.1-fpm
restart: on-failure
volumes:
- ../admin:/var/www/admin
working_dir: /var/www
env_file:
- ./variables/dev-admin.env
api:
container_name: api
image: php:7.1-fpm
restart: on-failure
volumes:
- ../api:/var/www/api
working_dir: /var/www
env_file:
- ./variables/dev-api.env
*.env ファイルの内容:
dev-api.env:
APP_ENV=DEV
VIRTUAL_HOST=api.host.dev
VIRTUAL_PORT=9000
dev-admin.env:
APP_ENV=DEV
VIRTUAL_HOST=admin.host.dev
VIRTUAL_PORT=9000
の内容/etc/nginx/conf.d/default.conf
:
# admin.host.dev
upstream admin.host.dev {
## Can be connect with "env_default" network
# admin
server 172.18.0.3:9000;
}
server {
server_name admin.host.dev;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
location / {
proxy_pass http://admin.host.dev;
}
}
# api.host.dev
upstream api.host.dev {
## Can be connect with "env_default" network
# api
server 172.18.0.4:9000;
}
server {
server_name api.host.dev;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
location / {
proxy_pass http://api.host.dev;
}
}
の全出力docker-compose up
:
sudo docker-compose up --remove-orphans
Recreating admin
Recreating nginx-proxy
Recreating api
Attaching to admin, api, nginx-proxy
admin | [19-Apr-2017 15:18:24] NOTICE: fpm is running, pid 1
admin | [19-Apr-2017 15:18:24] NOTICE: ready to handle connections
api | [19-Apr-2017 15:18:24] NOTICE: fpm is running, pid 1
api | [19-Apr-2017 15:18:24] NOTICE: ready to handle connections
nginx-proxy | forego | starting dockergen.1 on port 5000
nginx-proxy | forego | starting nginx.1 on port 5100
nginx-proxy | dockergen.1 | 2017/04/19 15:18:25 Generated '/etc/nginx/conf.d/default.conf' from 3 containers
nginx-proxy | dockergen.1 | 2017/04/19 15:18:25 Running 'nginx -s reload'
nginx-proxy | dockergen.1 | 2017/04/19 15:18:25 Watching docker events
nginx-proxy | dockergen.1 | 2017/04/19 15:18:25 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx-proxy | nginx.1 | 2017/04/19 15:18:35 [error] 26#26: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.60.1, server: api.host.dev, request: "GET / HTTP/1.1", upstream: "http://172.18.0.4:9000/", host: "api.host.dev"
nginx-proxy | nginx.1 | api.host.dev 192.168.60.1 - - [19/Apr/2017:15:18:35 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
nginx-proxy | nginx.1 | 2017/04/19 15:18:45 [error] 26#26: *3 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.60.1, server: admin.host.dev, request: "GET / HTTP/1.1", upstream: "http://172.18.0.3:9000/", host: "admin.host.dev"
nginx-proxy | nginx.1 | admin.host.dev 192.168.60.1 - - [19/Apr/2017:15:18:45 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
^[[A^[[Anginx-proxy | nginx.1 | 2017/04/19 15:24:47 [error] 26#26: *5 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.60.1, server: api.host.dev, request: "GET / HTTP/1.1", upstream: "http://172.18.0.4:9000/", host: "api.host.dev"
nginx-proxy | nginx.1 | api.host.dev 192.168.60.1 - - [19/Apr/2017:15:24:47 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"