diff --git a/container.go b/container.go index 9f1ad04490..044dbfa3ee 100644 --- a/container.go +++ b/container.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/pkg/archive" "github.com/docker/go-connections/nat" "github.com/pkg/errors" + "github.com/testcontainers/testcontainers-go/wait" ) @@ -69,6 +70,7 @@ type FromDockerfile struct { type ContainerRequest struct { FromDockerfile Image string + Entrypoint []string Env map[string]string ExposedPorts []string // allow specifying protocol info Cmd []string diff --git a/docker.go b/docker.go index dbe8bdddf5..ba8fd741cd 100644 --- a/docker.go +++ b/docker.go @@ -531,6 +531,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque } dockerInput := &container.Config{ + Entrypoint: req.Entrypoint, Image: tag, Env: env, ExposedPorts: exposedPortSet, @@ -600,7 +601,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque return c, nil } -//attemptToPullImage tries to pull the image while respecting the ctx cancellations. +// attemptToPullImage tries to pull the image while respecting the ctx cancellations. // Besides, if the image cannot be pulled due to ErrorNotFound then no need to retry but terminate immediately. func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pullOpt types.ImagePullOptions) error { var ( diff --git a/docker_test.go b/docker_test.go index 4acc7deb02..d75022e6de 100644 --- a/docker_test.go +++ b/docker_test.go @@ -1036,6 +1036,36 @@ func TestCMD(t *testing.T) { defer c.Terminate(ctx) } +func TestEntrypoint(t *testing.T) { + /* + echo a unique statement to ensure that we + can pass in an entrypoint to the ContainerRequest + and it will be run when we run the container + */ + + ctx := context.Background() + + req := ContainerRequest{ + Image: "alpine", + WaitingFor: wait.ForAll( + wait.ForLog("entrypoint override!"), + ), + Entrypoint: []string{"echo", "entrypoint override!"}, + } + + c, err := GenericContainer(ctx, GenericContainerRequest{ + ContainerRequest: req, + Started: true, + }) + + if err != nil { + t.Fatal(err) + } + + // defer not needed, but keeping it in for consistency + defer c.Terminate(ctx) +} + func ExampleDockerProvider_CreateContainer() { ctx := context.Background() req := ContainerRequest{