diff --git a/container.go b/container.go index ad524f94d0..df05d1d246 100644 --- a/container.go +++ b/container.go @@ -114,6 +114,7 @@ type ContainerRequest struct { WaitingFor wait.Strategy Name string // for specifying container name Hostname string + WorkingDir string // specify the working directory of the container ExtraHosts []string // Deprecated: Use HostConfigModifier instead Privileged bool // For starting privileged container Networks []string // for specifying network names diff --git a/docker.go b/docker.go index 4527067753..cc84b31fc3 100644 --- a/docker.go +++ b/docker.go @@ -999,6 +999,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque Cmd: req.Cmd, Hostname: req.Hostname, User: req.User, + WorkingDir: req.WorkingDir, } hostConfig := &container.HostConfig{ diff --git a/docker_test.go b/docker_test.go index b1ef1c2c81..e66dfdaf76 100644 --- a/docker_test.go +++ b/docker_test.go @@ -1059,6 +1059,34 @@ func TestEntrypoint(t *testing.T) { terminateContainerOnEnd(t, ctx, c) } +func TestWorkingDir(t *testing.T) { + /* + print the current working directory to ensure that + we can specify working directory in the + ContainerRequest and it will be used for the container + */ + + ctx := context.Background() + + req := ContainerRequest{ + Image: "docker.io/alpine", + WaitingFor: wait.ForAll( + wait.ForLog("/var/tmp/test"), + ), + Entrypoint: []string{"pwd"}, + WorkingDir: "/var/tmp/test", + } + + c, err := GenericContainer(ctx, GenericContainerRequest{ + ProviderType: providerType, + ContainerRequest: req, + Started: true, + }) + + require.NoError(t, err) + terminateContainerOnEnd(t, ctx, c) +} + func ExampleDockerProvider_CreateContainer() { ctx := context.Background() req := ContainerRequest{