Skip to content

Commit 3ac8e33

Browse files
authored
Merge pull request #513 from doringeman/fix-execInContainer
refactor(standalone): add asRoot parameter to execInContainer
2 parents 025fa20 + 47d67a9 commit 3ac8e33

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

cmd/cli/pkg/standalone/containers.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func copyDockerConfigToContainer(ctx context.Context, dockerClient *client.Clien
6868

6969
// Ensure the .docker directory exists
7070
mkdirCmd := "mkdir -p /home/modelrunner/.docker && chown modelrunner:modelrunner /home/modelrunner/.docker"
71-
if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd); err != nil {
71+
if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, false); err != nil {
7272
return err
7373
}
7474

@@ -82,17 +82,19 @@ func copyDockerConfigToContainer(ctx context.Context, dockerClient *client.Clien
8282

8383
// Set correct ownership and permissions
8484
chmodCmd := "chown modelrunner:modelrunner /home/modelrunner/.docker/config.json && chmod 600 /home/modelrunner/.docker/config.json"
85-
if err := execInContainer(ctx, dockerClient, containerID, chmodCmd); err != nil {
85+
if err := execInContainer(ctx, dockerClient, containerID, chmodCmd, false); err != nil {
8686
return err
8787
}
8888

8989
return nil
9090
}
9191

92-
func execInContainer(ctx context.Context, dockerClient *client.Client, containerID, cmd string) error {
92+
func execInContainer(ctx context.Context, dockerClient *client.Client, containerID, cmd string, asRoot bool) error {
9393
execConfig := container.ExecOptions{
94-
Cmd: []string{"sh", "-c", cmd},
95-
User: "root",
94+
Cmd: []string{"sh", "-c", cmd},
95+
}
96+
if asRoot {
97+
execConfig.User = "root"
9698
}
9799
execResp, err := dockerClient.ContainerExecCreate(ctx, containerID, execConfig)
98100
if err != nil {
@@ -453,10 +455,10 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
453455
}
454456
}
455457

456-
// Add proxy certificate to the system CA bundle
458+
// Add proxy certificate to the system CA bundle (requires root for update-ca-certificates)
457459
if created && proxyCert != "" {
458460
printer.Printf("Updating CA certificates...\n")
459-
if err := execInContainer(ctx, dockerClient, resp.ID, "update-ca-certificates"); err != nil {
461+
if err := execInContainer(ctx, dockerClient, resp.ID, "update-ca-certificates", true); err != nil {
460462
printer.Printf("Warning: failed to update CA certificates: %v\n", err)
461463
} else {
462464
printer.Printf("Restarting container to apply CA certificate...\n")

0 commit comments

Comments
 (0)