CARVIEW |
Select Language
HTTP/2 200
date: Mon, 28 Jul 2025 07:12:28 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"d823070f9764a8e9b8dae70becd97565"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=4dKxsPb5dFGkRJEV0CfBc3G9e9c%2FkjbLUjXdCRaoGF%2BcLUp2o2FKZ2KI4YRilG8XdHO0GF7iieNFNczepvskTwl0rVHOlCbbcltLdPMq9AXJzfkU%2FnQn%2FTFRtlPisAporWhrc4Sqepqd5LtwHBD4qRf48VQa1%2Fnb%2FeJDMFQ%2F9PE0x26R0lxTZY7DQnLJo%2Fziat%2F5d28Uip6KlsNYymYHlcmEgq5xcO1q8a%2BipZKY5VlZdPL3uxjyzzNS17X4GOFe8Kbf0r4uAdVfeEQGhThj5Q%3D%3D--WxE3C6n89Ztc9psq--DiZlCtv90Gh0oOe2EEXzNA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1819022896.1753686747; Path=/; Domain=github.com; Expires=Tue, 28 Jul 2026 07:12:27 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Tue, 28 Jul 2026 07:12:27 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 92AE:187A42:43BF61:554FDF:688722DB
Docker Exec Web Console · GitHub
Show Gist options
Save Humerus/0268c62f359f7ee1ee2d to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Created
April 16, 2015 00:09
-
Star
10
(10)
You must be signed in to star a gist -
Fork
9
(9)
You must be signed in to fork a gist
-
Save Humerus/0268c62f359f7ee1ee2d to your computer and use it in GitHub Desktop.
Docker Exec Web Console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> | |
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> | |
<script src="//cdn.rawgit.com/chjj/term.js/0b10f6c55d5113d50d0ff94b6c38a46375a5f9a5/src/term.js"></script> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<style> | |
body { | |
background-color: #000; | |
} | |
.terminal { | |
border: #000 solid 5px; | |
font-family: "DejaVu Sans Mono", "Liberation Mono", monospace; | |
font-size: 11px; | |
color: #f0f0f0; | |
background: #000; | |
} | |
.terminal-cursor { | |
color: #000; | |
background: #f0f0f0; | |
} | |
</style> | |
<script type="text/javascript"> | |
$(function() { | |
var websocket = new WebSocket("ws://" + window.location.hostname + ":" + window.location.port + "/exec/" + prompt("cid")); | |
websocket.onopen = function(evt) { | |
var term = new Terminal({ | |
cols: 100, | |
rows: 30, | |
screenKeys: true, | |
useStyle: true, | |
cursorBlink: true, | |
}); | |
term.on('data', function(data) { | |
websocket.send(data); | |
}); | |
term.on('title', function(title) { | |
document.title = title; | |
}); | |
term.open(document.getElementById('container-terminal')); | |
websocket.onmessage = function(evt) { | |
term.write(evt.data); | |
} | |
websocket.onclose = function(evt) { | |
term.write("Session terminated"); | |
term.destroy(); | |
} | |
websocket.onerror = function(evt) { | |
if (typeof console.log == "function") { | |
console.log(evt) | |
} | |
} | |
} | |
}); | |
</script> | |
</head> | |
<div id="container-terminal"></div> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/json" | |
"flag" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"net" | |
"net/http" | |
"net/http/httputil" | |
"time" | |
"github.com/davecgh/go-spew/spew" | |
"golang.org/x/net/websocket" | |
) | |
var port = flag.String("port", "8080", "Port for server") | |
var host = flag.String("host", "192.168.0.126:2735", "Docker host") | |
func main() { | |
flag.Parse() | |
http.Handle("/exec/", websocket.Handler(ExecContainer)) | |
http.Handle("/", http.FileServer(http.Dir("./"))) | |
if err := http.ListenAndServe(":"+*port, nil); err != nil { | |
panic(err) | |
} | |
} | |
func ExecContainer(ws *websocket.Conn) { | |
container := ws.Request().URL.Path[len("/exec/"):] | |
if container == "" { | |
ws.Write([]byte("Container does not exist")) | |
return | |
} | |
type stuff struct { | |
Id string | |
} | |
var s stuff | |
params := bytes.NewBufferString("{\"AttachStdin\":true,\"AttachStdout\":true,\"AttachStderr\":true,\"Tty\":true,\"Cmd\":[\"/bin/bash\"]}") | |
resp, err := http.Post("https://"+*host+"/containers/"+container+"/exec", "application/json", params) | |
if err != nil { | |
panic(err) | |
} | |
data, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
panic(err) | |
} | |
json.Unmarshal([]byte(data), &s) | |
if err := hijack(*host, "POST", "/exec/"+s.Id+"/start", true, ws, ws, ws, nil, nil); err != nil { | |
panic(err) | |
} | |
fmt.Println("Connection!") | |
fmt.Println(ws) | |
spew.Dump(ws) | |
} | |
func hijack(addr, method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, data interface{}) error { | |
params := bytes.NewBufferString("{\"Detach\": false, \"Tty\": true}") | |
req, err := http.NewRequest(method, path, params) | |
if err != nil { | |
return err | |
} | |
req.Header.Set("User-Agent", "Docker-Client") | |
req.Header.Set("Content-Type", "text/plain") | |
req.Header.Set("Connection", "Upgrade") | |
req.Header.Set("Upgrade", "tcp") | |
req.Host = addr | |
dial, err := net.Dial("tcp", addr) | |
// When we set up a TCP connection for hijack, there could be long periods | |
// of inactivity (a long running command with no output) that in certain | |
// network setups may cause ECONNTIMEOUT, leaving the client in an unknown | |
// state. Setting TCP KeepAlive on the socket connection will prohibit | |
// ECONNTIMEOUT unless the socket connection truly is broken | |
if tcpConn, ok := dial.(*net.TCPConn); ok { | |
tcpConn.SetKeepAlive(true) | |
tcpConn.SetKeepAlivePeriod(30 * time.Second) | |
} | |
if err != nil { | |
return err | |
} | |
clientconn := httputil.NewClientConn(dial, nil) | |
defer clientconn.Close() | |
// Server hijacks the connection, error 'connection closed' expected | |
clientconn.Do(req) | |
rwc, br := clientconn.Hijack() | |
defer rwc.Close() | |
if started != nil { | |
started <- rwc | |
} | |
var receiveStdout chan error | |
if stdout != nil || stderr != nil { | |
go func() (err error) { | |
if setRawTerminal && stdout != nil { | |
_, err = io.Copy(stdout, br) | |
} | |
return err | |
}() | |
} | |
go func() error { | |
if in != nil { | |
io.Copy(rwc, in) | |
} | |
if conn, ok := rwc.(interface { | |
CloseWrite() error | |
}); ok { | |
if err := conn.CloseWrite(); err != nil { | |
} | |
} | |
return nil | |
}() | |
if stdout != nil || stderr != nil { | |
if err := <-receiveStdout; err != nil { | |
return err | |
} | |
} | |
spew.Dump(br) | |
go func() { | |
for { | |
fmt.Println(br) | |
spew.Dump(br) | |
} | |
}() | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.
good job