Skip to content

Instantly share code, notes, and snippets.

func randomHexString(length int) (string, error) {
chars := "01234567890abcdef"
bytes := make([]byte, length)
for idx, _ := range bytes {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars))))
if err != nil {
return "", err
}
bytes[idx] = chars[num.Int64()]
}
$ curl 'http://localhost:4243/v1.10/version'
{"Arch":"amd64","GitCommit":3600720,"GoVersion":"go1.2.1","KernelVersion":"3.8.0-29-generic","Os":"linux","Version":"0.9.1"}
$ curl --no-buffer -X POST 'http://localhost:4243/v1.10/images/create?fromImage=ubuntu&tag='
{"status":"Pulling repository ubuntu"}
{"status":"Pulling image (raring) from ubuntu","progressDetail":{},"id":"eb601b8965b8"}{"status":"Pulling image (raring) from ubuntu, endpoint: https://cdn-registry-1.docker.io/v1/","progressDetail":{},"id":"eb601b8965b8"}{"status":"Pulling image (lucid) from ubuntu","progressDetail":{},"id":"9cc9ea5ea540"}{"status":"Pulling image (lucid) from ubuntu, endpoint: https://cdn-registry-1.docker.io/v1/","progressDetail":{},"id":"9cc9ea5ea540"}{"status":"Pulling image (saucy) from ubuntu","progressDetail":{},"id":"9f676bd305a4"}{"status":"Pulling image (saucy) from ubuntu, endpoint: https://cdn-registry-1.docker.io/v1/","progressDetail":{},"id":"9f676bd305a4"}{"status":"Pulling image (precise) from ubuntu","progressD
$ cat fig.yml
dckr:
image: ubuntu
command: ls -l /
volumes:
- /var/run/docker.sock:/docker.sock
$ fig run dckr bash
root@dac750a9bcb3:/# apt-get install -y netcat > /dev/null
root@dac750a9bcb3:/# nc -U /docker.sock
$ cat fig.yml
dckr:
image: ubuntu
command: ls /
volumes:
- /var/run/docker.sock:/docker.sock
$ fig up
Creating figldleworktest_dckr_1...
Attaching to figldleworktest_dckr_1
$ cat fig.yml
web:
build: ./web
command: find .
ports:
- 3000:3000
$ fig up
Recreating koafig_web_1...
Attaching to koafig_web_1
koafig_web_1 | .
$ cat fig.yml
web:
build: ./web
command: npm ls
ports:
- 3000:3000
$ fig up
Recreating koafig_web_1...
Attaching to koafig_web_1
koafig_web_1 | web@0.0.0 /code
@aanand
aanand / Dockerfile
Last active January 2, 2016 14:39
Dockerfile ADD caching bug
FROM ubuntu
ADD foo.txt /foo.txt
@aanand
aanand / gist:7677102
Created November 27, 2013 15:00
[BP][AEIOU](DM|MD)(AS|SA)
BADMAS
PADMAS
BEDMAS
PEDMAS
BIDMAS
PIDMAS
BODMAS
PODMAS
BUDMAS
PUDMAS
@aanand
aanand / about.md
Last active December 24, 2015 13:59
Docker attach timing bug

When starting and attaching to a container with a pseudo-tty, the initial bash prompt will only appear if the 'attach' request comes very quickly after the 'start' request (<0.1 seconds, in my tests).

Note how in the first run (attach immediately after starting), a chunk is received containing the prompt, but in the second run (start, then sleep 1s, then attach), it hangs after receiving the response headers.

This is an issue when trying to run a bash container from a Docker client that is geographically distant from the Docker server - the prompt doesn't appear, and you have to hit Enter to get one. From a UX standpoint, it appears as if Docker is simply hanging, which is pretty frustrating!

@aanand
aanand / gist:6795151
Last active December 24, 2015 11:59
Discrepancy in behaviour of docker run-with-immediate-attach vs run-and-then-attach
# Normal run, without -d.
# Container prompt appears immediately; after exiting, system prompt appears on new line.
$ docker run -i -t ubuntu bash
root@0b3fa3041e3f:/# exit
exit
$
# Now run with -d and *then* attach.
# Container prompt doesn't appear until I hit Enter; after exiting, system prompt appears on same line.