docker run -it gcr.io/... /bin/bash does not get SkyDNS settings in /etc/resolv.conf

9/12/2015

From a running pod on a GKE node I can:

# docker exec e68f1765f8b0 more /etc/resolv.conf 
::::::::::::::
/etc/resolv.conf
::::::::::::::
nameserver 10.103.240.10
nameserver 169.254.169.254
nameserver 10.10.0.1
search default.svc.cluster.local svc.cluster.local cluster.local c.dandsltd-gce.internal. 899692696219.google.internal. google.internal.
options ndots:5

But from the same GKE node, if I run:

# docker run  -it gcr.io/<same image> /bin/bash
root@ac81b13b172d:/# more /etc/resolv.conf 
domain c.dandsltd-gce.internal.
search c.dandsltd-gce.internal. 899692696219.google.internal. google.internal.
nameserver 169.254.169.254
nameserver 10.10.0.1

This threw me for a loop cause I thought SkyDNS was not running on my containers. Obviously, starting a pod/container from the replication controller is doing more stuff, like injecting the SkyDNS settings vs just a docker run.

Is there a way to run a one off docker container and get the same environment as a container started via the replication controller?

Thanks, Aaron

-- Aaron Bostick
google-kubernetes-engine

2 Answers

9/15/2015

What I really just needed to do was:

# docker exec e68f1765f8b0 bash

frmo the GKE node. Then I could get a shell from a container running in the cluster instead of a new container just running locally but not provisioned by kubernetes.

This way, something like SkyDNS is setup for you and you can test something like wget .default.cluster.local etc

-- Aaron Bostick
Source: StackOverflow

9/14/2015

You can run a one off container by creating a pod with restartPolicy: Never in the spec. Example: apiVersion: v1 kind: Pod metadata: name: nginx labels: name: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 restartPolicy: "Never"

With v1.1, kubectl will support creating one-off pods from an image via kubectl run $podname --image=$image --restart=Never. In the meantime, you have to create a pod from a file to specify restart policy.

-- jeffml
Source: StackOverflow