@@ -106,9 +106,10 @@ func GetShortcuts() []string {
106106 common .FormatSCHeader ("m" , "Monitor" ),
107107 common .FormatSCHeader ("v" , "Volumes" ),
108108 common .FormatSCHeader ("n" , "Networks" ),
109- common .FormatSCHeader ("shift-n" , "Attach Network" ),
110109 common .FormatSCHeader ("r" , "(Re)Start" ),
111110 common .FormatSCHeader ("p" , "Prune" ),
111+ common .FormatSCHeader ("shift-s" , "Root Shell" ),
112+ common .FormatSCHeader ("shift-n" , "Attach Network" ),
112113 common .FormatSCHeader ("ctrl-k" , "Stop" ),
113114 }
114115}
@@ -153,7 +154,14 @@ func InputHandler(v *view.ResourceView, event *tcell.EventKey) *tcell.EventKey {
153154 // Shell
154155 id , err := v .GetSelectedID ()
155156 if err == nil {
156- Shell (app , id )
157+ Shell (app , id , false )
158+ }
159+ return nil
160+ case 'S' :
161+ // Root Shell
162+ id , err := v .GetSelectedID ()
163+ if err == nil {
164+ Shell (app , id , true )
157165 }
158166 return nil
159167 case 'd' :
@@ -328,7 +336,7 @@ func Describe(app common.AppController, v *view.ResourceView) {
328336 app .OpenInspector (inspect .NewTextInspector ("Describe container" , subject , content , "json" ))
329337}
330338
331- func Shell (app common.AppController , id string ) {
339+ func Shell (app common.AppController , id string , asRoot bool ) {
332340 // Stop any background refresh to prevent UI updates interfering with the shell
333341 app .StopAutoRefresh ()
334342
@@ -355,7 +363,12 @@ func Shell(app common.AppController, id string) {
355363
356364 for _ , shell := range shells {
357365 // Check if shell exists
358- checkCmd := exec .Command ("docker" , "exec" , id , shell , "-c" , "exit 0" )
366+ var checkCmd * exec.Cmd
367+ if asRoot {
368+ checkCmd = exec .Command ("docker" , "exec" , "-u" , "root" , id , shell , "-c" , "exit 0" )
369+ } else {
370+ checkCmd = exec .Command ("docker" , "exec" , id , shell , "-c" , "exit 0" )
371+ }
359372 if err := checkCmd .Run (); err == nil {
360373 selectedShell = shell
361374 break
@@ -369,13 +382,22 @@ func Shell(app common.AppController, id string) {
369382 }
370383
371384 fmt .Print ("\033 [H\033 [2J" )
372- fmt .Printf ("Entering shell %s for %s (type 'exit' or CTRL+D to return)...\n " , selectedShell , id )
385+ shellMode := ""
386+ if asRoot {
387+ shellMode = " (root)"
388+ }
389+ fmt .Printf ("Entering shell %s%s for %s (type 'exit' or CTRL+D to return)...\n " , selectedShell , shellMode , id )
373390
374391 // Use proper PTY handling or simple command depending on platform
375392 // For basic usage, standard io connection is usually enough but Suspend/Restore is tricky
376393 // We MUST ensure tview is fully suspended
377394
378- cmd := exec .Command ("docker" , "exec" , "-it" , id , selectedShell )
395+ var cmd * exec.Cmd
396+ if asRoot {
397+ cmd = exec .Command ("docker" , "exec" , "-u" , "root" , "-it" , id , selectedShell )
398+ } else {
399+ cmd = exec .Command ("docker" , "exec" , "-it" , id , selectedShell )
400+ }
379401 cmd .Stdin = os .Stdin
380402 cmd .Stdout = os .Stdout
381403 cmd .Stderr = os .Stderr
0 commit comments