Oct 5, 2014

Docker 'Hello World' on Ubuntu

Docker seems very promising but I haven't seen enough any self-contained scripts that show off its capabilities. So I made one.

Given an Ubuntu machine this script installs Docker, pulls down a pre-made image, launches it in a container, hits the running web aplication, then shuts it down and deletes the container and then prints how much network traffic the whole operation took. ( set -v set -e eth0_bytes(){ grep eth0 /proc/net/dev | awk -F' ' '{print $2}'; } bytes_before=$(eth0_bytes) sudo /bin/sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" sudo /bin/sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -" sudo apt-get update sudo apt-get install -y lxc-docker sudo docker run --name=sweet -d -p 5000:5000 training/webapp python app.py until curl http://localhost:5000/ 2>/dev/null; do sleep 1; done curl http://localhost:5000/ sudo docker stop sweet sudo docker rm sweet bytes_after=$(eth0_bytes) printf "%.1fMB\n" $(echo "($bytes_after - $bytes_before) / (1024*1024)" | bc -l) )



Ryan Flynn is a programmer and problem solver.