moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.11k stars 1.14k forks source link

buildctl build RUN curl step failed, Could not resolve host #5412

Open alazalazalaz opened 1 day ago

alazalazalaz commented 1 day ago

I did the following step to recurrent the error:

step1、vi docker-compose.yaml

version: '2.1'
services:
    buildkitd:
      image: moby/buildkit:v0.16.0
      container_name: buildkitd
      privileged: true
      restart: always
      command: ["--addr", "tcp://0.0.0.0:1234"]

step2、run the container docker-compose -f docker-compose.yaml up -d buildkitd step3、entry the container docker exec -it 3a76a7e82807 /bin/sh step4、test the container network

/ # nslookup www.google.com
Server:     127.0.0.11
Address:    127.0.0.11:53

Non-authoritative answer:
Name:   www.google.com
Address: 172.217.163.36

Non-authoritative answer:
Name:   www.google.com
Address: 2404:6800:4012:4::2004

the network is OK.

step5、create a Dockerfile, vi Dockerfile (still in the container)

FROM alpine/curl

RUN nslookup www.google.com

step6、build the Dockerfile (still in the container) / # buildctl --addr=tcp://0.0.0.0:1234 build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --progress=plain step7、 encounter the ERROR!

#4 [1/2] FROM docker.io/alpine/curl:latest@sha256:a9599b0ecdab1fb3c798985836248c51ba27577218e93c99bcc1ec61969acaf8
#4 extracting sha256:1010f67b3369ce6414bb7f1ebaea67db6912f2d4045960ee5f5386e56196de8a 0.0s done
#4 DONE 7.6s

#5 [2/2] RUN nslookup www.google.com
#5 10.31 nslookup: can't connect to remote host: Address not available
#5 ERROR: process "/bin/sh -c nslookup www.google.com" did not complete successfully: exit code: 1
------
 > [2/2] RUN nslookup www.google.com:
10.31 nslookup: can't connect to remote host: Address not available
------
Dockerfile:3
--------------------
   1 |     FROM alpine/curl
   2 |
   3 | >>> RUN nslookup www.google.com
   4 |
--------------------
error: failed to solve: process "/bin/sh -c nslookup www.google.com" did not complete successfully: exit code: 1

machine info: Ubuntu 18.04.6 x86_64

cat /etc/resolv.conf on the Ubuntu machine:

nameserver 172.20.100.25
nameserver 172.20.100.27

the Ubuntu machine's network is perfectly fine.

cat /etc/resolv.conf in the container:

/ # cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0

other steps:

> [2/4] RUN curl -vvvv -s https://www.google.com:
0.223 * Could not resolve host: www.google.com
0.223 * shutting down connection #0

so, why the build command failed? Did i missed some config in the step 1?

alazalazalaz commented 19 hours ago

update. I added network_mode:bridge in step1, partial RUN command works fun now, such as nslookup wget apt. The curl command still failed, error : curl: (6) Could not resolve host: www.google.com