@@ -114,7 +114,18 @@ func NewDockerClient() (*DockerClient, error) {
114114
115115// ExecContainer executes a command inside a running container by name and returns the combined stdout/stderr.
116116func (dc * DockerClient ) ExecContainer (containerName string , command []string ) (string , error ) {
117- L .Info ().Strs ("Command" , command ).Str ("ContainerName" , containerName ).Msg ("Executing command" )
117+ execConfig := container.ExecOptions {
118+ Cmd : command ,
119+ AttachStdout : true ,
120+ AttachStderr : true ,
121+ }
122+
123+ return dc .ExecContainerOptions (containerName , execConfig )
124+ }
125+
126+ // ExecContainer executes a command inside a running container by name and returns the combined stdout/stderr.
127+ func (dc * DockerClient ) ExecContainerOptions (containerName string , execConfig container.ExecOptions ) (string , error ) {
128+ L .Info ().Strs ("Command" , execConfig .Cmd ).Str ("ContainerName" , containerName ).Msg ("Executing command" )
118129 ctx := context .Background ()
119130 containers , err := dc .cli .ContainerList (ctx , container.ListOptions {
120131 All : true ,
@@ -135,11 +146,6 @@ func (dc *DockerClient) ExecContainer(containerName string, command []string) (s
135146 return "" , fmt .Errorf ("container with name '%s' not found" , containerName )
136147 }
137148
138- execConfig := container.ExecOptions {
139- Cmd : command ,
140- AttachStdout : true ,
141- AttachStderr : true ,
142- }
143149 execID , err := dc .cli .ContainerExecCreate (ctx , containerID , execConfig )
144150 if err != nil {
145151 return "" , fmt .Errorf ("failed to create exec instance: %w" , err )
0 commit comments