Last active
September 7, 2021 02:56
-
-
Save relistan/3940bb66b4b0b903beed1fd4ebbcade8 to your computer and use it in GitHub Desktop.
block-docker-container
This file contains 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 ( | |
"fmt" | |
"io" | |
"os" | |
"github.com/fsouza/go-dockerclient" | |
) | |
func main() { | |
_, outwr := io.Pipe() | |
_, errwr := io.Pipe() | |
client, err := docker.NewClientFromEnv() | |
if err != nil { | |
fmt.Printf("Error connecting to Docker!: %s\n", err.Error()) | |
os.Exit(1) | |
} | |
fmt.Printf("Attaching to: %s\n", os.Args[1]) | |
err = client.AttachToContainer(docker.AttachToContainerOptions{ | |
Container: os.Args[1], | |
OutputStream: outwr, | |
ErrorStream: errwr, | |
Stdin: false, | |
Stdout: true, | |
Stderr: true, | |
Stream: true, | |
Success: make(chan struct{}), | |
}) | |
if err != nil { | |
fmt.Printf("Error attaching to container!: %s\n", err.Error()) | |
os.Exit(1) | |
} | |
for {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code will totally lock up the Docker container to which it is attached on Docker 1.10 or later. Any client can do this.