繁体   English   中英

Docker-连接到本地主机-连接被拒绝

[英]Docker - Connecting to localhost - connection refused

这是我的Dockerfile:

FROM sonatype/nexus3:latest
COPY ./scripts/ /bin/scripts/
RUN curl -u admin:admin123 -X GET 'http://localhost:8081/service/rest/v1/repositories'

运行构建后:

docker build -t test./

输入为:

(7) Failed connect to localhost:8081; Connection refused

为什么? 仅在运行后才可以向本地主机(正在构建的容器)发送请求? 还是我应该在Dockerfile中添加一些内容?

感谢帮助 :)

为什么要在构建服务时连接到该服务?

默认情况下,该服务尚未运行,您需要先启动容器。

去除卷曲并首先启动容器

docker run test 

Dockerfile是一种创建映像的方法,然后您可以从映像创建容器。 容器启动并运行后,端口即可使用。 因此,在构建图像时不能卷曲。

将Dockerfile更改为-

FROM sonatype/nexus3:latest
COPY ./scripts/ /bin/scripts/

建立图片-

 docker build -t test .

根据图片创建容器-

docker run -d  --name nexus -p 8081:8081 test 

现在查看您的容器是否正在运行并卷曲-

docker ps 
curl -u admin:admin123 -X GET 'http://localhost:8081/service/rest/v1/repositories'

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM