Skip to content

Instantly share code, notes, and snippets.

@relistan
Last active September 7, 2021 02:56
Show Gist options
  • Save relistan/3940bb66b4b0b903beed1fd4ebbcade8 to your computer and use it in GitHub Desktop.
Save relistan/3940bb66b4b0b903beed1fd4ebbcade8 to your computer and use it in GitHub Desktop.
block-docker-container
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 {}
}
@relistan
Copy link
Author

relistan commented May 4, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment