我的问题是我当前无法登录到在docker上运行的Web ap。我的docker-compose包括我的rails应用程序,一个mysql数据库,一个宁静的api和一个反向代理(最近有人帮我解决了这个问题!)。当前一切运行正常(或者至少我认为是这样),我什至可以通过转到localhost / api来测试我的api端点(然后我会看到api的文档)。
问题是,当我登录时,它通过了宁静的api,但出现如下错误:
Failed to open TCP connection to localhost:12345 (Cannot assign requested address - connect(2) for "localhost" port 12345)
我试图在docker-compose中公开端口,但是没有用。这是重要的文件:
docker-compose.yml
version: '3.5'
services:
app:
image: 'test/testapp:first-test'
depends_on:
- db
environment:
DB_USER: root
DB_NAME: test_dev
DB_PASSWORD: root
DB_HOST: db
DB_PORT: 3306
RAILS_ENV: development
ports:
- "3000:3000"
volumes:
- .:/test_app
networks:
test-network:
aliases:
- app
api:
depends_on:
- db
image: 'test/testapi:first-test'
ports:
- "12345:12345"
expose:
- "12345"
volumes:
- .:/test_api
networks:
test-network:
aliases:
- api
reverse-proxy:
depends_on:
- app
- api
image: nginx:alpine
volumes:
- $PWD/default.conf:/etc/nginx/conf.d/default.conf
networks:
test-network:
aliases:
- reverse-proxy
ports:
- 80:80
- 443:443
db:
image: mysql:latest
restart: always
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_dev
MYSQL_USERNAME: root
MYSQL_PASSWORD: root
ports:
- '3306:3306'
volumes:
- .:/test_db
networks:
test-network:
aliases:
- mysql-db
networks:
test-network:
nginx conf
# This is a default site configuration which will simply return 404, preventing
# chance access to any other virtualhost.
server {
listen 80 default_server;
listen [::]:80 default_server;
# Frontend
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://hubsite:3000; # same name as network alias
}
# Backend
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://hubapi:12345/; # <--- note this has an extra /
}
# location = /404.html {
# internal;
# }
}
现在这非常“ alpha”,我可以肯定我的卷都错了,我应该完全“链接”我的服务。
如果有人对此有任何信息,我将非常感谢!谢谢!