Skip to content

Commit

Permalink
Merge pull request #3 from grepplabs/host-dns
Browse files Browse the repository at this point in the history
Add DNSServer to docker component
  • Loading branch information
everesio committed Jan 29, 2018
2 parents 08602b5 + 4b49c1f commit ad50368
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -113,6 +113,7 @@ func TestWithDocker(t *testing.T) {
`http://{{ value . "it-vault.Host"}}:{{ value . "it-vault.Port"}}/v1/sys/seal-status`,
http.Options{},
),
DNSServer: "8.8.8.8",
},
)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion docker_client.go
Expand Up @@ -108,7 +108,7 @@ func (r *dockerClient) PullImage(imageName string) error {
}

// CreateContainer creates a new container.
func (r *dockerClient) CreateContainer(containerName string, image string, env []string, portSpecs []string, cmd []string, binds []string) (string, error) {
func (r *dockerClient) CreateContainer(containerName string, image string, env []string, portSpecs []string, cmd []string, binds []string, dnsServer string) (string, error) {
// ip:public:private/proto
exposedPorts, portBindings, err := nat.ParsePortSpecs(portSpecs)
if err != nil {
Expand All @@ -120,9 +120,15 @@ func (r *dockerClient) CreateContainer(containerName string, image string, env [
ExposedPorts: exposedPorts,
Cmd: typesStrslice.StrSlice(cmd),
}
dns := make([]string, 0)
if dnsServer != "" {
dns = append(dns, dnsServer)
}

hostConfig := typesContainer.HostConfig{
PortBindings: portBindings,
Binds: binds,
DNS: dns,
}

body, err := r.client.ContainerCreate(context.Background(), &config, &hostConfig, nil, containerName)
Expand Down
3 changes: 2 additions & 1 deletion docker_client_test.go
Expand Up @@ -50,7 +50,8 @@ func TestDockerCommands(t *testing.T) {
env := []string{}
cmd := []string{}
binds := []string{}
containerID, err := dc.CreateContainer(containerName, testImage, env, portSpecs, cmd, binds)
dnsServer := ""
containerID, err := dc.CreateContainer(containerName, testImage, env, portSpecs, cmd, binds, dnsServer)
a.Nil(err)

container, err := dc.GetContainerByID(containerID)
Expand Down
2 changes: 2 additions & 0 deletions docker_component.go
Expand Up @@ -18,6 +18,8 @@ type DockerComponent struct {
Cmd []string
// List of volume bindings for this container
Binds []string
// DNS server to lookup
DNSServer string
// Follow container log output
FollowLogs bool
// Callback invoked after start container command was invoked.
Expand Down
4 changes: 2 additions & 2 deletions docker_lifecycle_handler.go
Expand Up @@ -211,8 +211,8 @@ func (r *dockerLifecycleHandler) createDockerContainer(container *dockerContaine
cmd = append(cmd, container.Cmd...)
}

r.context.logger.Info.Println("Creating container for", container.Name, "name", containerName, "env", env, "portSpecs", portSpecs, "cmd", cmd, "binds", container.Binds)
containerID, err := r.dockerClient.CreateContainer(containerName, container.Image, env, portSpecs, cmd, container.Binds)
r.context.logger.Info.Println("Creating container for", container.Name, "name", containerName, "env", env, "portSpecs", portSpecs, "cmd", cmd, "binds", container.Binds, "dns", container.DNSServer)
containerID, err := r.dockerClient.CreateContainer(containerName, container.Image, env, portSpecs, cmd, container.Binds, container.DNSServer)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions test-examples/setup_docker_environment_test.go
Expand Up @@ -197,6 +197,7 @@ func newDockerEnvironment() *dit.DockerEnvironment {
`http://{{ value . "it-vault.Host"}}:{{ value . "it-vault.Port"}}/v1/sys/seal-status`,
http.Options{},
),
DNSServer: "8.8.8.8",
},
)
if err != nil {
Expand Down

0 comments on commit ad50368

Please sign in to comment.