Skip to content

Instantly share code, notes, and snippets.

@tvon
Created June 30, 2020 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvon/8351aaac45071aa927547c3af6b3099b to your computer and use it in GitHub Desktop.
Save tvon/8351aaac45071aa927547c3af6b3099b to your computer and use it in GitHub Desktop.
nsswitch / netdns
FROM golang:1 as builder
COPY . /src
WORKDIR /src
RUN go build -o /src/test
RUN /src/test
package main
import (
"net"
"fmt"
"os"
)
func main() {
f, err := os.OpenFile("/Users/tvon/hosts", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()
_, err = f.WriteString("\n127.0.0.1 totally-legit.website")
if err != nil {
fmt.Println(err)
}
conn, err := net.LookupHost("totally-legit.website")
if err != nil {
fmt.Println(err)
}
fmt.Println(conn)
}
@tvon
Copy link
Author

tvon commented Jun 30, 2020

Fails as expected (ignoring /etc/hosts):

docker build -t foobar .
Sending build context to Docker daemon  3.072kB
Step 1/5 : FROM golang:1 as builder
 ---> 5fbd6463d24b
Step 2/5 : COPY . /src
 ---> a49283d30be7
Step 3/5 : WORKDIR /src
 ---> Running in db79ff4629e1
Removing intermediate container db79ff4629e1
 ---> 043be4e3a602
Step 4/5 : RUN go build -o /src/test
 ---> Running in 9d8dd5fa1c48
Removing intermediate container 9d8dd5fa1c48
 ---> 53f0640c08b6
Step 5/5 : RUN /src/test
 ---> Running in 4e156a882332
invalid argument
lookup totally-legit.website on 192.168.65.1:53: no such host
[]
Removing intermediate container 4e156a882332
 ---> 3af9bdcb7795
Successfully built 3af9bdcb7795
Successfully tagged foobar:latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment