How do we ship our applications?
virtualenv
and some glue.7. There's a new openssl package out, very urgent security issue!
Oh, and we're also stuck if one of those apps gets exploited, or tries to use all the resources on the box...
Progress! But, 'the computer' is a very chunky unit of abstraction.
Cool! "Process Virtualization Not Server Virtualization."
Sort of.
“Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application.”
Tons of people!
$ sudo docker
* By BLAMMO I mean that docker containers start fast enough that for some workloads you can afford to create or start them on demand, which makes your effective density far, far higher.
“We've switched to Docker from Vagrant/Virtualbox to isolate test runs on our CI server. We have seen major speed improvements in some cases, but mostly we are seeing much more stable runs with fewer tests that just randomly fail on CI, or cases where the VM would stop responding completely or fail to launch.”
-- Dan Ivovich
vagrant@precise64:~/docker$ sudo docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
vagrant@precise64:~/docker$ sudo docker run -i -t ubuntu:12.10 bash
root@7f407e484d62:/# apt-get update
# lots of apt-get stuff
root@7f407e484d62:/# apt-get install redis-server
# lots of apt-get stuff
root@7f407e484d62:/# exit
vagrant@precise64:~/docker$ sudo docker ps -a
ID IMAGE COMMAND CREATED STATUS PORTS
7f407e484d62 ubuntu:12.10 bash 56 seconds ago Exit 0
vagrant@precise64:~/docker$ sudo docker commit -m "installed redis server" 7f407e484d62 jbarratt/redis01
517800321f48
vagrant@precise64:~/docker$ sudo docker images
REPOSITORY TAG ID CREATED SIZE
ubuntu 12.04 8dbd9e392a96 6 months ago 131.5 MB (virtual 131.5 MB)
ubuntu 12.10 b750fe79269d 7 months ago 24.65 kB (virtual 180.1 MB)
ubuntu latest 8dbd9e392a96 6 months ago 131.5 MB (virtual 131.5 MB)
ubuntu precise 8dbd9e392a96 6 months ago 131.5 MB (virtual 131.5 MB)
ubuntu quantal b750fe79269d 7 months ago 24.65 kB (virtual 180.1 MB)
jbarratt/redis01 latest 517800321f48 56 seconds ago 98.46 MB (virtual 278.6 MB)
vagrant@precise64:~/docker$ sudo docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
vagrant@precise64:/var$ sudo docker run -p 6379 -d -i \
-t jbarratt/redis01 /usr/bin/redis-server
8222ea69d3a3
vagrant@precise64:/var$ sudo docker ps
ID IMAGE COMMAND PORTS
8222ea69d3a3 jbarratt/redis01:latest /usr/bin/redis-server 49153->6379
vagrant@precise64:/var$ telnet 172.17.42.1 49153
Connected to 172.17.42.1.
Escape character is '^]'.
> rpush users josh
> rpush users sam
> rpush users susan
> llen users
:3
> lrange users 0 5
josh sam susan
vagrant@precise64:/var$ sudo docker attach 8222ea69d3a3
[1] 23 Oct 00:06:36 - DB 0: 1 keys (0 volatile) in 4 slots HT.
[1] 23 Oct 00:06:36 - 0 clients connected (0 slaves), 791000 bytes in use
...
vagrant@precise64:/var$ ps xwf
495 ? Ss 0:00 /bin/sh -e -c /usr/bin/docker -d /bin/sh
496 ? Sl 0:24 \_ /usr/bin/docker -d
3115 pts/1 Ss+ 0:00 \_ lxc-start -n 8222ea(...) -f /var/lib/docker/
3120 pts/1 Sl+ 0:48 \_ /usr/bin/redis-server
vagrant@precise64:/var$ sudo lxc-attach -n 8222ea(...)
fc51fae86a46603bc3762 /bin/bash
root@8222ea69d3a3:/var# ps auxwwf
USER PID TTY STAT START TIME COMMAND
root 1 ? Sl+ Oct22 0:52 /usr/bin/redis-server
root@precise64:/var/lib/docker/containers# ls
15f3c09e26eef579dfa53035fbdde536f07fb124c473b146df73fd4c7f2be33c
7a3dad48db07177ffdd6ae77104585a3a0f43d88400f4c3affc258685c835dd0
7f407e484d62e50ce05c14c83d47b136d590f37054084a44f3370a721bb0116a
8222ea69d3a344edd2a734423c53ef17dc4de194bb4fc51fae86a46603bc3762
root@precise64:/var/lib/docker/containers# ls 8222(...)
bb4fc51fae86a46603bc3762/rw/
dump.rdb
root@precise64:/var/lib/docker/containers# docker diff 8222
A /dump.rdb
vagrant@precise64:/var$ sudo lxc-attach -n 8222(...) /bin/bash
root@8222ea69d3a3:/var# mkdir /foo && touch /foo/bar
root@8222ea69d3a3:/var# exit
vagrant@precise64:~# docker diff 8222
A /dump.rdb
A /foo
A /foo/bar
vagrant@precise64~$ sudo docker images -viz | dot -Tpng -o docker.png
root@precise64:~# cat /sys/fs/cgroup/cpuacct/lxc/8222(...)/cpuacct.usage
63976740039
root@precise64:~# cat /sys/fs/cgroup/cpuacct/lxc/8222(...)/cpuacct.usage
63986569761
root@precise64:~# cat /sys/fs/cgroup/memory/lxc/8222(...)/memory.usage_in_bytes
2433024
root@precise64:~# cat /sys/fs/cgroup/memory/lxc/8222(...)/memory.limit_in_bytes
9223372036854775807
root@precise64:~# docker stop 8222
root@precise64:~# time docker start 8222
real 0m0.150s
root@precise64:~# time service redis-server start
Starting redis-server: redis-server.
real 0m0.165s
root@precise64:~# time docker run -p 6379 -d -i -t jbarratt/redis01 /usr/bin/redis-server
real 0m0.147s
# redis image
# VERSION 0.1
FROM ubuntu:12.10
MAINTAINER Joshua Barratt jbarratt@serialized.net
RUN apt-get -qq update
RUN apt-get install -y redis-server
EXPOSE 6379
CMD ["/usr/bin/redis-server"]
vagrant@precise64:/vagrant/redis$ sudo docker build -t jbarratt/redis-dockerfile .
Uploading context 10240 bytes
Step 1 : FROM ubuntu:12.10
---> b750fe79269d
Step 2 : MAINTAINER Joshua Barratt jbarratt@serialized.net
---> Using cache
---> 0501ea3da390
Step 3 : RUN apt-get -qq update
---> Using cache
---> 134cfdc556cb
Step 4 : RUN apt-get install -y redis-server
---> Using cache
---> 01ba2afd847f
Step 5 : EXPOSE 6379
---> Using cache
---> 9ac5730000e7
Step 6 : CMD ["/usr/bin/redis-server"]
---> Running in 713d6ab6d7d8
---> 60d75fbc2eac
Successfully built 60d75fbc2eac
vagrant@precise64:/vagrant/redis$ sudo docker run jbarratt/redis-dockerfile
vagrant@precise64:/vagrant/redis$ sudo docker ps
ID IMAGE COMMAND PORTS
bbd790b7dfcd jbarratt/redis-dockerfile:latest /usr/bin/redis-server 49162->6379
FROM jbarratt/redis-dockerfile
MAINTAINER Joshua Barratt jbarratt@serialized.net
ADD fixtures.sh /tmp/fixtures.sh
RUN /tmp/fixtures.sh
#!/bin/bash
/usr/bin/redis-server &
for ((i=1; i <=100; i++))
do
redis-cli rpush numbers $i
done
redis-cli shutdown
vagrant@precise64:/vagrant/redis-fixture$ sudo docker build -t jbarratt/redis-fixture .
Uploading context 10240 bytes
Step 1 : FROM jbarratt/redis-dockerfile
---> 60d75fbc2eac
Step 2 : MAINTAINER Joshua Barratt jbarratt@serialized.net
---> Running in 0d8bf423b2bc
---> a5c3e1b51ceb
Step 3 : ADD fixtures.sh /tmp/fixtures.sh
---> c4170f7490e1
Step 4 : RUN /tmp/fixtures.sh
---> Running in 0ca9a42ca15d
[10] 23 Oct 05:21:32 - Client closed connection
[10] 23 Oct 05:21:32 - Accepted 127.0.0.1:54281
[10] 23 Oct 05:21:32 # User requested shutdown...
[10] 23 Oct 05:21:32 * Saving the final RDB snapshot before exiting.
[10] 23 Oct 05:21:32 * DB saved on disk
[10] 23 Oct 05:21:32 # Redis is now ready to exit, bye bye...
---> 835789acdc85
Successfully built 835789acdc85
vagrant@precise64:/vagrant/redis-fixture$ sudo docker run jbarratt/redis-fixture
[8] 23 Oct 05:28:30 * The server is now ready to accept connections on port 6379
[8] 23 Oct 05:28:31 - DB 0: 1 keys (0 volatile) in 4 slots HT.
vagrant@precise64:/vagrant/redis-fixture$ sudo docker ps
ID IMAGE STATUS PORTS
8eced7aaefbf jbarratt/redis-fixture:latest Up 28 seconds 49173->6379
bbd790b7dfcd jbarratt/redis-dockerfile:latest Up 25 minutes 49162->6379
vagrant@precise64:/vagrant/redis-fixture$ redis-cli -p 49173
redis 127.0.0.1:49173> lrange numbers 0 5
1) "2" 2) "3" 3) "4" 4) "5" 5) "6" 6) "7"
#!/bin/bash
if [ $# -eq 0 ]
then; echo "Usage: ./rebuilt.sh (tag)"; exit; fi
if [[ $EUID -ne 0 ]]
then ; echo "Docker needs sudo or root." ; exit ; fi
OLDCONTAINER=$(docker ps | grep $1 | cut -d ' ' -f 1)
if [ -z $OLDCONTAINER ]
then
echo "No container found tagged $1"
exit
fi
docker build -t $1 .
docker stop $OLDCONTAINER
docker run -d $1
vagrant@precise64:~/docker-registry$ sudo docker pull crosbymichael/ipython
Pulling repository crosbymichael/ipython
5c69fc56f7ef: Download complete
b83fe8498b94: Download complete
e7162f69e18e: Download complete
....
vagrant@precise64:~/docker-registry$ sudo docker run -d crosbymichael/ipython
5bcdaa4f7a2f
vagrant@precise64:~/docker-registry$ sudo docker ps
ID IMAGE COMMAND PORTS
5bcdaa4f7a2f crosbymichael/ipython:latest /bin/sh -c ipython n 49155->8888
$ docker pull samalba/wordpress
$ docker pull samalba/mysql
$ heat stack-create wordpress -f templates/wordpress_mysql.yml
$ heat stack-list
+--------------------------------------+------------+-----------------+
| id | stack_name | stack_status |
+--------------------------------------+------------+-----------------+
| 239cc009-00fe-4c6f-ac67-f8873df38f08 | wordpress | CREATE_COMPLETE |
+--------------------------------------+------------+-----------------+
docker ps
ID IMAGE COMMAND PORTS
5513c532b4dc samalba/wordpress:latest /usr/sbin/apache2 -D 49174->80
b98d764d109d samalba/mysql:latest /start_mysqld.sh 49173->3306
Hybrid Workloads. Cool.
curl http://get.docker.io | sudo sh
Or
# Install vagrant, then...
$ git clone https://github.com/dotcloud/docker.git
$ vagrant up
$ vagrant ssh
$ sudo docker
FROM ubuntu
MAINTAINER Joshua Barratt jbarratt@serialized.net
RUN apt-get -qq update
RUN apt-get install -y python3
ADD talk /talk
EXPOSE 8080:8080
WORKDIR /talk
CMD ["python3", "-m", "http.server", "8080"]