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 (ie the place where Dockerfile is located)
FROM busybox
RUN curl -L http://localhost/latest/myfile -o /root/myfile
I get errror:
$ docker build -t archlinux/test .
... from localhost : Failed to connect to localhost port 80: Connection refused
So how to do it.
Solution: to use localhost/file
Use IP of the localhost for that change the
Listen 127.0.0.1:80 to Listen 80
Or
Best solution is use --network=host
docker build --network=host -t test .
This curl request has some deeper sense?
Dockerfile can be used anywhere (not only in your machine). For example, I would like to download the Dockerfile and build an image based on this file... I need to serve a resource(myfile) with a www server and run docker build with --network=host
parameter - a bit annoying.
I think you should use COPY
command for this job.
如果您在 Linux 上使用 Docker,则在运行docker run
或docker build
命令时需要使用--network="host"
作为参数,那么您的主机的 localhost 127.0.0.1
将可供您的 docker 容器访问。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.