主机Web浏览器无法访问Docker容器

时间:2020-08-30 17:54:53

标签: docker google-chrome

我在Docker容器中执行了一项服务,并将容器端口Launching lib\main.dart on AOSP on IA Emulator in debug mode... lib/services/database.dart:68:49: Error: The argument type 'String/*1*/' can't be assigned to the parameter type 'String/*2*/'. - 'String/*1*/' is from 'package:time_tracking_andrea_udemy_project/services/database.dart' ('lib/services/database.dart'). - 'String/*2*/' is from 'dart:core'. final jobsCollection = _instance.collection(path); ^ lib/services/database.dart:72:45: Error: The argument type 'Map<String/*1*/, dynamic>' can't be assigned to the parameter type 'Map<String/*2*/, dynamic>'. - 'Map' is from 'dart:core'. - 'String/*1*/' is from 'dart:core'. - 'String/*2*/' is from 'package:time_tracking_andrea_udemy_project/services/database.dart' ('lib/services/database.dart'). .map((document) => builder(document.data())) 暴露给主机端口8080。 命令:

6000

docker run \ -d \ --rm \ --name keycloak \ -p 6000:8080 \ -e KEYCLOAK_USER=admin \ -e KEYCLOAK_PASSWORD=admin \ quay.io/keycloak/keycloak \ -b 0.0.0.0 \ -Djboss.http.port=8080

的结果
docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 71c6a8ea6529 quay.io/keycloak/keycloak "/opt/jboss/tools/do…" About an hour ago Up About an hour 8443/tcp, 0.0.0.0:6000->8080/tcp keycloak

的结果
docker inspect keycloak

"Ports": { "8080/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "6000" } ], "8443/tcp": null },

的结果
ps aux | grep docker

当我使用root 1481 0.0 0.5 1600328 83560 ? Ssl 18:17 0:02 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock root 2995 0.0 0.0 549300 4448 ? Sl 18:18 0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 6000 -container-ip 172.17.0.2 -container-port 8080 root 3009 0.0 0.0 109104 5140 ? Sl 18:18 0:00 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/71c6a8ea6529bdcb1a04d5fa73b5ca0053a4d012905d592b6b342f1b0e8c9047 -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc 时,它可以到达容器内的服务。 curl

curl -v http://localhost:6000/auth

当我尝试在google-chrome网络浏览器中执行相同操作时,出现了错误:

*   Trying 127.0.0.1:6000...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 6000 (#0)
> GET /auth/ HTTP/1.1
> Host: localhost:6000
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: no-cache, must-revalidate, no-transform, no-store
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Referrer-Policy: no-referrer
< Content-Security-Policy: frame-src 'self'; frame-ancestors 'self'; object-src 'none';
< Date: Sun, 30 Aug 2020 17:44:03 GMT
< Connection: keep-alive
< X-Robots-Tag: none
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< X-Content-Type-Options: nosniff
< Content-Type: text/html;charset=utf-8
< Content-Length: 4070

为什么Google Chrome浏览器无法使用This site can’t be reached The webpage at http://localhost:6000/auth/ might be temporarily down or it may have moved permanently to a new web address. ERR_UNSAFE_PORT 和公开端口访问docker服务?

1 个答案:

答案 0 :(得分:1)

默认情况下,X11使用端口6000,因此Chrome认为端口6000不安全(有关其他不安全,被阻止的端口的列表,请参见here,有关说明,请参见here)。

您需要将其更改为安全的端口之一,或按以下方式启动Chrome:

chrome --explicitly-allowed-ports=6000