You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to execute certain command inside of docker swarm containers from another go service. But when executing it, I am getting the exit code 126 while inspecting.
Here is the code used for reference
funcinspectDockerContainer(cli*client.Client, containerIdstring) error{
execConfig:= types.ExecConfig{
Cmd: []string{"nginx -t && nginx -s reload"},
}
execResponse, err:=cli.ContainerExecCreate(context.Background(), containerID, execConfig)
iferr!=nil {
fmt.Println("Error creating container exec", err)
returnerr
}
err=cli.ContainerExecStart(context.Background(), execResponse.ID, types.ExecStartCheck{})
iferr!=nil {
fmt.Println("Error creating container exec start", err)
returnerr
}
hijackedResp, err:=cli.ContainerExecAttach(context.Background(), execResponse.ID, types.ExecStartCheck{})
iferr!=nil {
fmt.Errorf("Error attaching container %w", err)
hijackedResp.Close()
returnerr
}
varhasErrboolfor {
execInfo, err:=cli.ContainerExecInspect(context.Background(), execResponse.ID)
...ifexecInfo.ExitCode!=0 {
fmt.Println("Finished with exitCode: ", execInfo.ExitCode)
break
}
}
returnnil
}
funcinspectService(cli*client.Client, serviceNamestring) error{
// Get the list of tasks (containers) for the specified servicetasks, err:=cli.TaskList(context.Background(), types.TaskListOptions{Filters: filters.NewArgs(filters.Arg("service", serviceName))})
iferr!=nil {
returnfmt.Errorf("error while listing docker tasks %w", err)
}
// Execute a command in each container of the servicefor_, task:=rangetasks {
fmt.Println("Task Status: ", task.Status.State)
iftask.Status.State!="running" {
continue
}
containerID:=task.Status.ContainerStatus.ContainerIDinspectDockerContainer(containerID)
}
returnnil
}
It works fine when running these services on docker compose and passing command to nginx container.
But fails with exit code of 126 when running the same command in docker swarm containers.
Is there some restriction that i am not aware of that blocks the access of swarm container through docker engine api. Both nginx service and golang service are running as root users, golang service has access to docker daemon and all the services are sharing the same overlay networks.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to execute certain command inside of docker swarm containers from another go service. But when executing it, I am getting the exit code 126 while inspecting.
Here is the code used for reference
It works fine when running these services on docker compose and passing command to nginx container.
But fails with exit code of 126 when running the same command in docker swarm containers.
Is there some restriction that i am not aware of that blocks the access of swarm container through docker engine api. Both nginx service and golang service are running as root users, golang service has access to docker daemon and all the services are sharing the same overlay networks.
Beta Was this translation helpful? Give feedback.
All reactions