Docker:无法连接到本地主机端口80:连接被拒绝 [英] Docker: Failed to connect to localhost port 80: Connection refused
问题描述
在构建时我的docker文件中,我想从本地服务器访问主机上的文件,而不是将它们复制到docker context文件夹(即Dockerfile所在的位置)
In my docker file while building i want to access files on my host machine from localhost server rather than copying them to the docker context folder (i.e the place where Dockerfile is located)
FROM busybox
RUN curl -L http://localhost/latest/myfile -o /root/myfile
我得到了错误:
$ docker build -t archlinux/test .
... from localhost : Failed to connect to localhost port 80: Connection refused
那怎么做.
解决方案::使用 localhost/file
使用本地主机的IP进行更改
Use IP of the localhost for that change the
Listen 127.0.0.1:80 to Listen 80
或
最好的解决方案是使用-network = host
Best solution is use --network=host
docker build --network=host -t test .
推荐答案
如果您正在使用Docker for Linux,则在运行时需要使用-network ="host"
作为参数 docker run
或 docker build
命令,则您的docker容器将可以访问主机的本地主机 127.0.0.1
.
If you are using Docker for Linux, You would need to use --network="host"
as argument when you are running docker run
or docker build
command, then your host machine's localhost 127.0.0.1
will be accessible to your docker container.
这篇关于Docker:无法连接到本地主机端口80:连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!