15 octobre 2014

docker exec preview

A new feature to come in docker 1.3 I'm waiting for is docker exec command. This one will make docker-enter hack an official command. This command will let you attach a new process to an existing container, for diagnostic or monitoring purpose (for sample) or some more advanced hacks I have in mind :-D

As I wanted to test it before official release, I had to check how to build Docker from latest sources.

Docker build system is based on Docker. Don't ask me how debian folks can follow their "build from source" principle, anyway it makes our life easier.

On my Ubuntu box, I just had to clone docker git repository and run make binary to get the latest an greatest docker binary and give it a try, but I wanted also to get it on my good old MacBook.

make cross is designed to build alternate docker binaries for non linux/x64 systems (i386, arm, darwin, freebsd). It works well, but then I need to retrieve the generated binary from the build container.

I'm using boot2docker with VirtualBox guest additions, waiting for 1.3 to offer this by default. But when ran remotely (in boot2docker VM) the Makefile require to setup a BIND directory for docker working copy to be mounted in the container at expected location. I wasn't able to make it work, for some odd reason the dind script fail to start.

Anyway, David gave me to find a workaround.

make build gives me the container image ID for an environment ready to build docker from sources. I can then run a (privileged) container, equivalent to the one ran by make binary,  as a shell and run the hack/make.sh cross command by myself. As a result, this container has all the cross-compiled binaries build in bundles folder.

I then run another docker command from OSX to retrieve the built OSX binary form the (still running) build container : 
docker cp 987654321:/go/src/github.com/docker/docker/bundles/1.2.0-dev/cross/darwin/amd64/docker-1.2.0-dev/docker ./docker-osx

So I now have docker client 1.2.0-dev (a java developer would name it "1.3.0-SNAPSHOT") available on my OS.

I have to do the same on my boot2docker VM so it run 1.2.0-dev daemon. Just need to stop the docker daemon and replace /usr/local/bin/docker. Please note this change won't be persisted if you restart the boot2docker VM. Would need to build a custom iso, but I'm lazy here :-P

Anyway, I now can play with the new docker exec command

➜  docker-1.2.0-dev ./docker version
Client version: 1.2.0-dev
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): dc243c8
OS/Arch (client): darwin/amd64
Server version: 1.2.0-dev
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): dc243c8
➜  docker-1.2.0-dev ./docker run -d ubuntu sleep 1000
fc17ce405dba8417d7995218bd142041877cadcf49751f2233aecf01a7c25114
➜  docker-1.2.0-dev ./docker exec -it fc17 bash
root@fc17ce405dba:/# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 13:44 ?        00:00:00 sleep 1000
root         7     0  4 13:44 ?        00:00:00 bash
root        21     7  0 13:44 ?        00:00:00 ps -ef
root@fc17ce405dba:/# 

I organize a local edition of Docker Global Hack Day on october 30th. Hacking with such a new command is an option to experiment with new usages and design some crazy tool. Join !