Skip to content

Commit

Permalink
feat: add extra hosts option
Browse files Browse the repository at this point in the history
  • Loading branch information
Haegi committed Dec 20, 2022
1 parent 279694e commit c2e37d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func (d *docker) createContainer(ctx context.Context, image string, ports NamedP
AutoRemove: true,
Privileged: cfg.Privileged,
Mounts: mounts,
ExtraHosts: cfg.ExtraHosts,
}

resp, err := d.client.ContainerCreate(ctx, containerConfig, hostConfig, nil, nil, cfg.ContainerName)
Expand Down
12 changes: 12 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ func WithContainerReuse() Option {
}
}

// WithExtraHosts allows to provide custom entries to the hosts file of the container.
// It is similar to the `--add-host` flag of docker.
func WithExtraHosts(hosts []string) Option {
return func(o *Options) {
o.ExtraHosts = hosts
}
}

// HealthcheckFunc defines a function to be used to determine container health.
// It receives a host and a port, and returns an error if the container is not
// ready, or nil when the container can be used. One example of HealthcheckFunc
Expand Down Expand Up @@ -291,6 +299,10 @@ type Options struct {
// {"username":"foo","password":"bar"}
Auth string `json:"auth"`

// ExtraHosts allows to add entries to the hosts file of the container.
// It is similar to the `--add-host` flag of docker.
ExtraHosts []string `json:"extraHosts"`

// Reuse prevents the container from being automatically stopped and enables
// its re-use in posterior executions.
Reuse bool `json:"reuse"`
Expand Down

0 comments on commit c2e37d8

Please # to comment.