简体   繁体   English

无法从 MacOS 上的主机浏览器连接到 Docker 容器

[英]Unable to connect to the Docker Container from the host browser on MacOS

I' am trying to deploy docker container on Mac machine.我正在尝试在 Mac 机器上部署 docker 容器。 I ran the command:我运行了命令:

     docker run -P -it clickstream-collector_csapi -c "test_config.yml".
     output: ts=2020-02-24T17:25:43Z lvl=info msg="Starting Collector"
     ts=2020-02-24T17:25:43Z lvl=info msg="Start producer" service=collector           
     brokers=kafka.dev:9102
     ts=2020-02-24T17:25:44Z lvl=info msg="Starting HTTP service"
     ts=2020-02-24T17:25:44Z lvl=info msg="Starting server on" addr=0.0.0.0:13425

However I can't launch 0.0.0.0:13425 on my Mac , it shows me "This site can't be reached0.0.0.0 refused to connect".但是,我无法在 Mac 上启动 0.0.0.0:13425,它显示“无法访问此站点 0.0.0.0 拒绝连接”。 It looks like my local machine doesn't look the docker .看起来我的本地机器看起来不像 docker 。 I know that Mac has some peculiarities but I pointed -p ( as I thought it should enough).我知道 Mac 有一些特点,但我指出 -p (因为我认为它应该足够了)。 Thanks a lot beforehand预先非常感谢

The docker run -P (capital “P”) option asks Docker to pick a host port. docker run -P (大写“P”)选项要求 Docker 选择一个主机端口。 That will almost always be a different port number from the one inside the container.这几乎总是与容器内的端口号不同。 You can print out the port number by using docker ps to find the container ID, and then docker port 0123456789ab to print out the actual port mapping.可以通过docker ps查找容器 ID 打印出端口号,然后docker port 0123456789ab打印出实际的端口映射。 Once you've found the port number, you can use the special hostname localhost or the matching special IP address 127.0.0.1 and that port number to reach your container (not 0.0.0.0, a special address that means “everywhere”).找到端口号后,您可以使用特殊主机名localhost或匹配的特殊 IP 地址 127.0.0.1 和该端口号来访问您的容器(不是 0.0.0.0,一个表示“无处不在”的特殊地址)。

In typical use you'll explicitly specify both host and container ports with a -p (little “p”) option, and also specify a --name so that you can find the container later.在典型使用中,您将使用-p (小“p”)选项显式指定主机和容器端口,并指定一个--name以便您稍后可以找到容器。

docker run \
  -it \
  -p 13425:13425 \
  --name clickstream_collector \
  clickstream-collector_csapi \
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker OSX:从容器连接到主机端口 - Docker OSX: Connect to a host port from a container Docker for mac 1.12.0:如何从容器连接到主机 - Docker for mac 1.12.0: how to connect to host from container 如何从主机上的 docker exec 的 pid 中检索 docker 容器名称(MacOS) - How to retrieve docker container name from pid of docker exec on the host (MacOS) 无法连接到 jenkins docker 容器内的 docker 容器 MacOS - Can't connect to docker inside jenkins docker container MacOS 如何以非 root 用户身份从 docker 容器内部访问 /var/run/docker.sock? (MacOS 主机) - How to access /var/run/docker.sock from inside a docker container as a non-root user? (MacOS Host) 从Docker容器登录macOS中的syslog / console? - Log to syslog / console in macOS from Docker container? 如何从主机外部(同一网络)连接到docker容器[OSX 10.11] - How to connect to a docker container from outside the host (same network) [OSX 10.11] 使用 --network=host 在 MacOS 上运行 docker 容器时如何访问主机上的端口? - How to access a port on the host machine when running docker container on MacOS with --network=host? 从主机连接到 mongo docker 容器 - Connecting to mongo docker container from host 从主机远程连接到容器中的数据库? - Remotely connect to Database in Container from Host Machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM