lost and found ( for me ? )

Ubuntu 13.04: docker

I am newbie to docker.
just referred to http://docs.docker.io/en/latest/installation/ubuntulinux/#ubuntu-raring

# tail -1 /etc/lsb-release ;uname –ri
DISTRIB_DESCRIPTION="Ubuntu 13.04"
3.8.0-35-generic x86_64

I have disabled UFW.
# ufw status
Status: inactive

install extra kernel to enable AUFS.
apt-get update;apt-get install linux-image-extra-`uname -r`

add a key
# sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -"
OK

add a dokcer repository.
# sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/
apt/sources.list.d/docker.list"

# cat /etc/apt/sources.list.d/docker.list
deb http://get.docker.io/ubuntu docker main

install docker
# apt-get update
# apt-get install lxc-docker –y

# dpkg -l lxc-docker
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                  Version         Architecture    Description
+++-=====================-===============-===============-===============================================
ii  lxc-docker            0.7.3           amd64           Linux container runtime

start a container.
root@ubuntu-1:~# docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu' (tag: latest) locally
Pulling repository ubuntu
8dbd9e392a96: Download complete
b750fe79269d: Download complete
27cf78414709: Download complete
root@f14cf363cce8:/#   <- in the container

on the host
the container has been started by “lxc-start”.
root@ubuntu-1:~# ps aux | grep docker | grep -v grep
root      5674  5.2  0.1 506956 12852 ?        Sl   21:18   0:08 /usr/bin/docker -d
root      5745  0.0  0.0 188840  4580 pts/0    Sl+  21:19   0:00 docker run -i -t ubuntu /bin/bash
root      5766  0.0  0.0  25576  1320 pts/6    Ss   21:19   0:00 lxc-start -n f14cf363cce861fdf0b4d8945623b85b07be96a0581d7b1c7bbf2adc25b718bd -f /var/lib/docker/containers/f14cf363cce861fdf0b4d8945623b85b07be96a0581d7b1c7bbf2adc25b718bd/config.lxc -- /.dockerinit -g 172.17.42.1 -i 172.17.0.2/16 -mtu 1500 -- /bin/bash

root@f14cf363cce8:/# tail -1 /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
root@f14cf363cce8:/# uname -ri
3.8.0-35-generic x86_64
root@f14cf363cce8:/# exit  <- exit from the container
exit
root@ubuntu-1:~#

[ small app, hello world ]

confirm docker is running as daemon.
# ps aux | grep docker | grep -v grep
root      5674  2.0  0.1 506956 12872 ?        Sl   21:18   0:08 /usr/bin/docker -d

download ubuntu image
root@ubuntu-1:~# docker pull ubuntu
Pulling repository ubuntu
8dbd9e392a96: Download complete
b750fe79269d: Download complete
27cf78414709: Download complete

run “/bin/echo hello world” in the ubuntu container.
# docker run ubuntu /bin/echo hello world
hello world

start the container.
root@ubuntu-1:~# CONTAINER_ID=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done")

root@ubuntu-1:~# echo $CONTAINER_ID
799830d6cd7743d49a4e11d50434729a1972b7d54630932e035c71ae76c4f18f

dump the logs.
# docker logs $CONTAINER_ID
hello world
hello world
hello world
hello world
<snip>

dump logs in real-time
root@ubuntu-1:~# docker attach $CONTAINER_ID
hello world
hello world
hello world
hello world
^Croot@ubuntu-1:~#

press Ctrl-C

after pressing Ctrl-C, the container stopped..
root@ubuntu-1:~# docker attach $CONTAINER_ID
2014/01/06 20:37:34 Impossible to attach to a stopped container, start it first

root@ubuntu-1:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

start the container again.
root@ubuntu-1:~# CONTAINER_ID=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done")

root@ubuntu-1:~# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
9d3898d6ebc4        ubuntu:12.04        /bin/sh -c while tru   4 seconds ago       Up 4 seconds                            clever_heisenberg
root@ubuntu-1:~#

root@ubuntu-1:~# docker stop $CONTAINER_ID

root@ubuntu-1:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

# docker info
Containers: 5
Images: 3
Driver: aufs
Root Dir: /var/lib/docker/aufs
Dirs: 13

root@ubuntu-1:/var/lib/docker# ls /var/lib/docker/
aufs  containers  graph  init  linkgraph.db  lxc-start-unconfined  repositories-aufs  volumes

root@ubuntu-1:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               8dbd9e392a96        8 months ago        128 MB
ubuntu              latest              8dbd9e392a96        8 months ago        128 MB
ubuntu              precise             8dbd9e392a96        8 months ago        128 MB
ubuntu              12.10               b750fe79269d        9 months ago        175.3 MB
ubuntu              quantal             b750fe79269d        9 months ago        175.3 MB
base                latest              b750fe79269d        9 months ago        175.3 MB
base                ubuntu-12.10        b750fe79269d        9 months ago        175.3 MB
base                ubuntu-quantal      b750fe79269d        9 months ago        175.3 MB
base                ubuntu-quantl       b750fe79269d        9 months ago        175.3 MB

[ Python web app container ( hello flask web app image ) ]

download shykes/pybuilder dokcer image.
# docker pull shykes/pybuilder


# docker images -tree
tq8dbd9e392a96 Virtual Size: 128 MB Tags: ubuntu:12.04, ubuntu:latest, ubuntu:precise
mq27cf78414709 Virtual Size: 175.3 MB
 mqb750fe79269d Virtual Size: 175.3 MB Tags: ubuntu:12.10, ubuntu:quantal, base:latest, base:ubuntu-12.10, base:ubuntu-quantal, base:ubuntu-quantl
   mq127455573097 Virtual Size: 175.3 MB
     mq3c0e53c2b843 Virtual Size: 271.8 MB
       mq7f01ac3ad392 Virtual Size: 311.8 MB
         mq938e27a84c9a Virtual Size: 362.7 MB
           mq20d238b4f7f3 Virtual Size: 550.4 MB
             mqc4c36c680c00 Virtual Size: 550.4 MB
               mq370fed31f16a Virtual Size: 550.4 MB Tags: shykes/pybuilder:latest

build python web app container.
root@ubuntu-1:~# URL=http://github.com/shykes/helloflask/archive/master.tar.gz

root@ubuntu-1:~# BUILD_JOB=$(sudo docker run -d -t shykes/pybuilder:latest /usr/local/bin/buildapp $URL)

root@ubuntu-1:~# sudo docker attach -sig-proxy=false $BUILD_JOB
  Creating /usr/local/lib/python2.7/dist-packages/setuptools.pth
Successfully installed Flask Jinja2 Werkzeug distribute
Cleaning up...

root@ubuntu-1:~# docker ps -a
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS              PORTS               NAMES
e6aecbe95dbe        shykes/pybuilder:latest   /usr/local/bin/build   2 minutes ago       Exit 0                                  loving_feynmann

create a new container.
root@ubuntu-1:~# BUILD_IMG=$(sudo docker commit $BUILD_JOB _/builds/github.com/shykes/helloflask/master)

root@ubuntu-1:~# echo $BUILD_IMG
3a942d759ac8bf6133d79bad56c2c9c9c2c2b285fea02963a6186c9ea4270891

root@ubuntu-1:~# WEB_WORKER=$(sudo docker run -d -p 5000 $BUILD_IMG /usr/local/bin/runapp)

root@ubuntu-1:~# echo $WEB_WORKER
0d74e6460cd99a6d8d6f4bf18fecd3def2be83c5af74cb307550ffe248afcf5b

running?
root@ubuntu-1:~# docker ps –a
CONTAINER ID        IMAGE                                                 COMMAND                CREATED             STATUS              PORTS                     NAMES
0d74e6460cd9        _/builds/github.com/shykes/helloflask/master:latest   /usr/local/bin/runap   2 minutes ago       Up 2 minutes        0.0.0.0:49153->5000/tcp   naughty_wright

root@ubuntu-1:~# docker logs $WEB_WORKER
* Running on http://0.0.0.0:5000/

root@ubuntu-1:~# WEB_PORT=$(sudo docker port $WEB_WORKER 5000 | awk -F: '{ print $2 }')
root@ubuntu-1:~# echo $WEB_PORT
49153

root@ubuntu-1:~# docker port $WEB_WORKER

Usage: docker port CONTAINER PRIVATE_PORT

Lookup the public-facing port which is NAT-ed to PRIVATE_PORT

root@ubuntu-1:~# docker port $WEB_WORKER 5000
0.0.0.0:49153

flask app is running in the container.
# curl http://127.1:49153
Hello world!


root@ubuntu-1:~# ps aux | grep docker | grep -v grep
root      5674  0.4  0.0 639628 11464 ?        Sl   21:18   0:20 /usr/bin/docker -d
root      7326  0.0  0.0  25576  1324 ?        Ss   22:25   0:00 lxc-start -n 0d74e6460cd99a6d8d6f4bf18fecd3def2be83c5af74cb307550ffe248afcf5b -f /var/lib/docker/containers/0d74e6460cd99a6d8d6f4bf18fecd3def2be83c5af74cb307550ffe248afcf5b/config.lxc -- /.dockerinit -g 172.17.42.1 -i 172.17.0.8/16 -mtu 1500 -- /usr/local/bin/runapp

stop the container.
root@ubuntu-1:~# docker ps
CONTAINER ID        IMAGE                                                 COMMAND                CREATED             STATUS              PORTS                     NAMES
0d74e6460cd9        _/builds/github.com/shykes/helloflask/master:latest   /usr/local/bin/runap   9 minutes ago       Up 9 minutes        0.0.0.0:49153->5000/tcp   naughty_wright

root@ubuntu-1:~# docker stop 0d74e6460cd9
0d74e6460cd9
root@ubuntu-1:~#

nnn, I need to study docker more, I’m getting lost about some of docker options..

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.