找不到8080端口。 (Docker, docker-compose) 错误
Can't find 8080 port. (Docker, docker-compose) Error
我认为这是一个代理问题,因为我仍然可以使用 localhost 域连接到 8380。但是错误是不同的。
Error: connect ECONNREFUSED 127.0.0.1:8080
这是我的 docker-compose 文件。我设置了 docker 覆盖网络,但它也无济于事。我认为这是代理问题。
version: '3'
services:
testidpsaml:
image: kristophjunge/test-saml-idp
environment:
- SIMPLESAMLPHP_SP_ENTITY_ID=urn:asdasd
- SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE=http://localhost:8446/login/callback
ports:
- 8380:8080
- 8333:8443
saml-enabled-reverse-proxy:
build: ./saml-enabled-reverse-proxy
ports:
- 8446:8446
networks:
- my_net
app:
build: ./adssa
volumes:
- /Users/jbaek:/asd/src
ports:
- 8080:8080
networks:
- my_net
networks:
my_net:
申请中,
...
var samlStrategy = new saml.Strategy({
// config options here
callbackUrl: 'http://localhost:8446/login/callback', //we don't use this?
// 8380 WORKS? WHY? WHY I CAN'T Connect
entryPoint: 'http://localhost:8380/simplesaml/saml2/idp/SSOService.php',
...
app.get('/',
function(req, res) {
apiProxy.web(req, res, {target: serviceProvider});
}
);
...
var server = app.listen(8446, function () {
console.log('Listening on port %d', server.address().port)
});
当您定义 ports:- 8380:8080
时,它会将 testidpsaml
的 8080
端口发布到主机的 8380
端口。然后,在 docker 主机(不是容器)上,您可以使用 localhost:8380
.
访问它
但是,在app
服务中,你的代码在运行容器中,那么localhost
不是docker host
,而是当前容器,你可以指定替换localhost
与您的 docker host ip
一起工作。
其实你也可以直接指定服务名,因为compose会为你设置a custom network:
User-defined bridges provide automatic DNS resolution between containers.
其中有一个内部dns服务器,可以帮助容器快速找到eathother,不需要使用docker主机传递流量容器。对于您的情况,请使用下一个:
entryPoint: 'http://testidpsaml:8080/simplesaml/saml2/idp/SSOService.php'
By default Compose sets up a single network for your app. Each
container for a service joins the default network and is both
reachable by other containers on that network, and discoverable by
them at a hostname identical to the container name.
因此在您的情况下,所有服务 testidpsaml,saml-enabled-reverse-proxy
... 都将在单一网络上。
并且您可以使用主机名作为服务名从另一项服务访问一项服务。
例如:在 testidpsaml 中访问您的应用服务
http://app:8080/contextpath/apipath
当你定义端口 8380:8080
时,这意味着你正在将 8080 从容器转发到主机中的 8380。
主机中将提供与
相同的应用服务
http://app:8380/contextpath/apipath
请相应地更改您的入口点。
您可以阅读更多关于 Networking here
我认为这是一个代理问题,因为我仍然可以使用 localhost 域连接到 8380。但是错误是不同的。
Error: connect ECONNREFUSED 127.0.0.1:8080
这是我的 docker-compose 文件。我设置了 docker 覆盖网络,但它也无济于事。我认为这是代理问题。
version: '3'
services:
testidpsaml:
image: kristophjunge/test-saml-idp
environment:
- SIMPLESAMLPHP_SP_ENTITY_ID=urn:asdasd
- SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE=http://localhost:8446/login/callback
ports:
- 8380:8080
- 8333:8443
saml-enabled-reverse-proxy:
build: ./saml-enabled-reverse-proxy
ports:
- 8446:8446
networks:
- my_net
app:
build: ./adssa
volumes:
- /Users/jbaek:/asd/src
ports:
- 8080:8080
networks:
- my_net
networks:
my_net:
申请中,
...
var samlStrategy = new saml.Strategy({
// config options here
callbackUrl: 'http://localhost:8446/login/callback', //we don't use this?
// 8380 WORKS? WHY? WHY I CAN'T Connect
entryPoint: 'http://localhost:8380/simplesaml/saml2/idp/SSOService.php',
...
app.get('/',
function(req, res) {
apiProxy.web(req, res, {target: serviceProvider});
}
);
...
var server = app.listen(8446, function () {
console.log('Listening on port %d', server.address().port)
});
当您定义 ports:- 8380:8080
时,它会将 testidpsaml
的 8080
端口发布到主机的 8380
端口。然后,在 docker 主机(不是容器)上,您可以使用 localhost:8380
.
但是,在app
服务中,你的代码在运行容器中,那么localhost
不是docker host
,而是当前容器,你可以指定替换localhost
与您的 docker host ip
一起工作。
其实你也可以直接指定服务名,因为compose会为你设置a custom network:
User-defined bridges provide automatic DNS resolution between containers.
其中有一个内部dns服务器,可以帮助容器快速找到eathother,不需要使用docker主机传递流量容器。对于您的情况,请使用下一个:
entryPoint: 'http://testidpsaml:8080/simplesaml/saml2/idp/SSOService.php'
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
因此在您的情况下,所有服务 testidpsaml,saml-enabled-reverse-proxy
... 都将在单一网络上。
并且您可以使用主机名作为服务名从另一项服务访问一项服务。
例如:在 testidpsaml 中访问您的应用服务
http://app:8080/contextpath/apipath
当你定义端口 8380:8080
时,这意味着你正在将 8080 从容器转发到主机中的 8380。
主机中将提供与
相同的应用服务http://app:8380/contextpath/apipath
请相应地更改您的入口点。
您可以阅读更多关于 Networking here