Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
env emits DOCKER_HOST_IP
Browse files Browse the repository at this point in the history
This is useful because it can be used in `docker-compose.yml` to make a
container's external port bind to the Docker host's public IP address.

See:
docker/compose#2915 (comment)
  • Loading branch information
msabramo committed Feb 14, 2016
1 parent 1eaf5a4 commit fdfa7ca
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
envTmpl = `{{ .Prefix }}DOCKER_TLS_VERIFY{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}{{ .Prefix }}DOCKER_CERT_PATH{{ .Delimiter }}{{ .DockerCertPath }}{{ .Suffix }}{{ .Prefix }}DOCKER_MACHINE_NAME{{ .Delimiter }}{{ .MachineName }}{{ .Suffix }}{{ if .NoProxyVar }}{{ .Prefix }}{{ .NoProxyVar }}{{ .Delimiter }}{{ .NoProxyValue }}{{ .Suffix }}{{end}}{{ .UsageHint }}`
envTmpl = `{{ .Prefix }}DOCKER_TLS_VERIFY{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST_IP{{ .Delimiter }}{{ .DockerHostIP }}{{ .Suffix }}{{ .Prefix }}DOCKER_CERT_PATH{{ .Delimiter }}{{ .DockerCertPath }}{{ .Suffix }}{{ .Prefix }}DOCKER_MACHINE_NAME{{ .Delimiter }}{{ .MachineName }}{{ .Suffix }}{{ if .NoProxyVar }}{{ .Prefix }}{{ .NoProxyVar }}{{ .Delimiter }}{{ .NoProxyValue }}{{ .Suffix }}{{end}}{{ .UsageHint }}`
)

var (
Expand All @@ -34,6 +34,7 @@ type ShellConfig struct {
Suffix string
DockerCertPath string
DockerHost string
DockerHostIP string
DockerTLSVerify string
UsageHint string
MachineName string
Expand Down Expand Up @@ -86,6 +87,11 @@ func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) {
return nil, fmt.Errorf("Error checking TLS connection: %s", err)
}

dockerHostIP, err := host.Driver.GetIP()
if err != nil {
return nil, err
}

userShell, err := getShell(c.String("shell"))
if err != nil {
return nil, err
Expand All @@ -94,6 +100,7 @@ func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) {
shellCfg := &ShellConfig{
DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), host.Name),
DockerHost: dockerHost,
DockerHostIP: dockerHostIP,
DockerTLSVerify: "1",
UsageHint: defaultUsageHinter.GenerateUsageHint(userShell, os.Args),
MachineName: host.Name,
Expand Down

0 comments on commit fdfa7ca

Please sign in to comment.