alpine-DNS-problem

Many softwares use alpine as their run-time base image.

Recently I set up a docker registry with portus as its front. But I came up with a problem that, registry won’t post date: 2017-12-06 title: alpine-DNS-problem

Firstly I thought it was a bug of docker resigtry, but as I’m digging into its code, I found that it’s actruely a bug of alpine linux. Alpine linux doesn’t have an /etc/nsswitch.conf config file.

So, I have to add an extra config file to alpine.

hosts:	files dns

Mount your host OS’ /etc/nsswitch.conf to the container or build a new alpine image with this config file in it:

FROM alpine:latest
RUN echo "hosts:	files dns" > /etc/nsswitch.conf
... other parts...

Wiki of nsswitch.conf: man nsswitch.conf


Tools I used to dig the bug:

  • ngrep: sudo ngrep -q kfd.me

  • golang:alpine: docker run --rm -ti -v $(pwd):/go golang:alpine go run /go/main.go

  • docker: docker run --rm -ti alpine nc -lkp 8083

  • nc: nc -lkp 8083

  • dnsmasq: local DNS server

  • the best IDE of the whole universe: VS Code

  • main.go:

package main
	
import (
	"net/http"
)

func main() {
	c := http.DefaultClient
	resp, err := c.Post("http://kfd.me:8083", "X", nil)
	if err != nil {
		panic(err)
	}
	panic(resp.Status)
}
comments powered by Disqus