!!! Docker
[{TableOfContents }]
!! Resources
* [https://docs.docker.com]
* [Dockerfile reference|https://docs.docker.com/reference/builder/]
* [docker public registry|https://registry.hub.docker.com/]
Install with {{apt-get install docker.io}}. Beware that you need a 64bit version OS !
!! docker options
{{{
root@athena:~# docker
Usage: docker [OPTIONS] COMMAND [arg...]
-H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use
A self-sufficient runtime for linux containers.
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from the containers filesystem to the host path
diff Inspect changes on a container's filesystem
events Get real time events from the server
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container
kill Kill a running container
load Load an image from a tar archive
login Register or Login to the docker registry server
logs Fetch the logs of a container
port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
pause Pause all processes within a container
ps List containers
pull Pull an image or a repository from the docker registry server
push Push an image or a repository to the docker registry server
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image in the docker index
start Start a stopped container
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the docker version information
wait Block until a container stops, then print its exit code
root@athena:~#
}}}
!! run
Then simply start a container with :
{{{docker run -i -t ubuntu /bin/bash}}}
This starts a container in interactive mode. The first time you run this, the image is downloaded from docker hub and stored locally. \\
When you exit the container, it is immediately "gone" too.
With {{docker ps}} you can see what is running:
{{{
root@athena:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9539bc7b78df ubuntu-14.04:latest /bin/bash 6 seconds ago Up 5 seconds silly_darwin
}}}
Now, the funny thing is, you can do something in the container, like installing vim or openjdk-7-jdk, and then commit that (from outside the container) :
{{{
root@athena:~# docker commit -m "added java" -a "Harry Metske" e5acc9ff7c9c ubuntu-14.04
feb996bac7c44edd0cfe28b54901f2ff500b4c18fed203931b703d14cc89b8c0
}}}
And after that you can see the results with {{docker images}} :
{{{
root@athena:~# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu-14.04 latest feb996bac7c4 12 seconds ago 664.2 MB
ubuntu/1404 v1.0 9e7a0bc71946 42 minutes ago 311.2 MB
ubuntu latest 5506de2b643b 6 days ago 199.3 MB
}}}
After that you can run that new container again (and have java installed) :
{{{
docker run -h hostje -i -t --user=metskem feb996bac7c4
}}}
* -h gives a hostname to the container (inside container)
* -i -t ==> interactive mode
* --user=metskem ==> start the shell with that user (that user must have been created earlier in the container)
* feb996bac7c4 ==> the unique id of the just committed image
!! run with port mapping
{{{
docker run -p 8080:80 -t -i dfda109aba4a /bin/bash
}}}
You can now access localhost:8080 on the host, this will be remapped to port 80 in the container.
!! history
You can also list the history of images:
{{{
root@athena:~# docker history feb996bac7c4
IMAGE CREATED CREATED BY SIZE
feb996bac7c4 41 minutes ago /bin/bash 353 MB
9e7a0bc71946 About an hour ago /bin/bash 112 MB
5506de2b643b 6 days ago /bin/sh -c #(nop) CMD [/bin/bash] 0 B
22093c35d77b 6 days ago /bin/sh -c apt-get update && apt-get dist-upg 6.558 MB
3680052c0f5c 6 days ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kB
e791be0477f2 6 days ago /bin/sh -c rm -rf /var/lib/apt/lists/* 0 B
ccb62158e970 6 days ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 194.8 kB
d497ad3926c8 9 days ago /bin/sh -c #(nop) ADD file:3996e886f2aa934dda 192.5 MB
511136ea3c5a 16 months ago 0 B
}}}
Note that no daemons are started after starting the container. For example, installing openssh-server (and update-rc.d defaults) it is not started after running the container ''==> find out, there must be other options''
!! build images
Create {{ /var/lib/docker/docker/dockerfiles/testje/Dockerfile}}, {{cd to /var/lib/docker/docker/dockerfiles}} and create testje/Dockerfile with content :
{{{
FROM nginx
MAINTAINER Harry Metske <harry.metske@gmail.com>
RUN date > /tmp/date.txt
RUN apt-get -y install vim
}}}
There is [Docker file Reference|https://docs.docker.com/reference/builder/#dockerfile-reference]
and run
{{{
root@athena:/var/lib/docker/dockerfiles# docker build testje
Sending build context to Docker daemon 2.56 kB
Sending build context to Docker daemon
Step 0 : FROM nginx
---> f1c42afeb4a4
Step 1 : MAINTAINER Harry Metske <harry.metske@gmail.com>
---> Using cache
---> 2db2a6377c41
Step 2 : RUN date > /tmp/date.txt
---> Using cache
---> d57d03dacc7f
Step 3 : RUN apt-get -y install vim
---> Using cache
---> e426018fc315
Successfully built e426018fc315
}}}
Another Dockerfile :
{{{
FROM nginx
MAINTAINER Harry Metske <harry.metske@gmail.com>
RUN apt-get -y install wget vim openssh-server openjdk-7-jre
RUN wget -O - http://apache.proserve.nl/tomcat/tomcat-8/v8.0.14/bin/apache-tomcat-8.0.14.tar.gz | gunzip | tar -x -C /usr/local
RUN cd /usr/local && ln -s apache-tomcat-8.0.14 tomcat
RUN rm -f /usr/local/tomcat/bin/*.bat
ADD filestoadd/tomcat-users.xml /usr/local/tomcat/conf/
CMD /bin/bash
}}}
!! More experiments
__docker pull centos:7__
{{{
[root@localhost ~]# docker pull centos:7
Pulling repository centos
dade6cb4530a: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
Status: Downloaded newer image for centos:7
}}}
__docker images__
{{{
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos 7 dade6cb4530a 2 weeks ago 224 MB
centos centos7 dade6cb4530a 2 weeks ago 224 MB
centos latest dade6cb4530a 2 weeks ago 224 MB
}}}
Create a docker file first in {{~/dockerfiles/java7/Dockerfile}} :
{{{
#
# Dockerfile with OpenJDK7 on top of CentoS 7
#
FROM dade6cb4530a
MAINTAINER Harry Metske <harry.metske@gmail.com>
RUN yum -y install java-1.7.0-openjdk
CMD /bin/bash
}}}
__docker build --tag=java7 --rm=true java7__
{{{
[root@localhost dockerfiles]# docker build --tag=java7 --rm=true java7
Sending build context to Docker daemon 2.56 kB
Sending build context to Docker daemon
Step 0 : FROM dade6cb4530a
---> dade6cb4530a
Step 1 : MAINTAINER Harry Metske <harry.metske@gmail.com>
---> Using cache
---> 359721211f5c
Step 2 : RUN yum -y install java-1.7.0-openjdk
---> Running in f21bde92b3d8
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror.denit.net
* extras: mirror.widexs.nl
* updates: mirror.widexs.nl
Resolving Dependencies
--> Running transaction check
---> Package java-1.7.0-openjdk.x86_64 1:1.7.0.75-2.5.4.2.el7_0 will be installed
------- a lot of yum output --------
xorg-x11-fonts-Type1.noarch 0:7.5-9.el7
Complete!
---> dee61328998e
Removing intermediate container f21bde92b3d8
Step 3 : CMD /bin/bash
---> Running in 45449ac928c8
---> e48c60e07bc1
Removing intermediate container 45449ac928c8
Successfully built e48c60e07bc1
}}}
__docker images__ again:
{{{
[root@localhost dockerfiles]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
java7 latest e48c60e07bc1 9 minutes ago 487.5 MB
centos centos7 dade6cb4530a 2 weeks ago 224 MB
centos latest dade6cb4530a 2 weeks ago 224 MB
centos 7 dade6cb4530a 2 weeks ago 224 MB
}}}
Now we have the first layer, CentOS with Java installed.
On top of that we want tomcat installed and make that a new build again with the following Dockerfile :
{{{
#
# Dockerfile for a running tomcat 8.0.18 on top OpenJDK7 on top of CentoS 7
# Also install tar, needed for unpacking the tomcat archive.
#
FROM e48c60e07bc1
MAINTAINER Harry Metske <harry.metske@gmail.com>
RUN yum -y install tar
RUN curl http://apache.proserve.nl/tomcat/tomcat-8/v8.0.18/bin/apache-tomcat-8.0.18.tar.gz | gunzip | tar -x -C /usr/local
RUN cd /usr/local && ln -s apache-tomcat-8.0.18 tomcat
RUN rm -rf /usr/local/tomcat/bin/*.bat /usr/local/tomcat/webapps/examples /usr/local/tomcat/webapps/host-manager
#
# by default we start the Tomcat container when the docker container is started.
CMD /usr/local/tomcat/bin/catalina.sh run
}}}
__docker build --force-rm=true --tag=tomcat8 tomcat8__
{{{
[root@localhost dockerfiles]# docker build --force-rm=true --tag=tomcat8 tomcat8
Sending build context to Docker daemon 3.072 kB
Sending build context to Docker daemon
Step 0 : FROM e48c60e07bc1
---> e48c60e07bc1
Step 1 : MAINTAINER Harry Metske <harry.metske@gmail.com>
---> Running in af0b22f64d21
---> c63db74da65c
Removing intermediate container af0b22f64d21
Step 2 : RUN yum -y install tar
---> Running in feb87054efdd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.denit.net
* extras: mirror.widexs.nl
* updates: mirror.widexs.nl
Resolving Dependencies
--> Running transaction check
---> Package tar.x86_64 2:1.26-29.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
----- a lot of yum output ----
Running transaction
Installing : 2:tar-1.26-29.el7.x86_64 1/1
Verifying : 2:tar-1.26-29.el7.x86_64 1/1
Installed:
tar.x86_64 2:1.26-29.el7
Complete!
---> 3b2d250a33dc
Removing intermediate container feb87054efdd
Step 3 : RUN curl http://apache.proserve.nl/tomcat/tomcat-8/v8.0.18/bin/apache-tomcat-8.0.18.tar.gz | gunzip | tar -x -C /usr/local
---> Running in 23ab3815b77e
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9053k 100 9053k 0 0 610k 0 0:00:14 0:00:14 --:--:-- 750k
---> e7f295ac6dc2
Removing intermediate container 23ab3815b77e
Step 4 : RUN cd /usr/local && ln -s apache-tomcat-8.0.18 tomcat
---> Running in 4b9e840d022d
---> be2444c2a7f1
Removing intermediate container 4b9e840d022d
Step 5 : RUN rm -f /usr/local/tomcat/bin/*.bat
---> Running in 4e3895b23dd7
---> 1690fcce7177
Removing intermediate container 4e3895b23dd7
Step 6 : CMD /usr/local/tomcat/bin/startup.sh
---> Running in baa7d280864e
---> f4af0b5bcc33
Removing intermediate container baa7d280864e
Successfully built f4af0b5bcc33
}}}
__docker images__ again :
{{{
[root@localhost dockerfiles]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tomcat8 latest f4af0b5bcc33 2 minutes ago 515.1 MB
java7 latest e48c60e07bc1 18 minutes ago 487.5 MB
<none> <none> c54971cf4c5c 34 minutes ago 502.7 MB
centos 7 dade6cb4530a 2 weeks ago 224 MB
centos centos7 dade6cb4530a 2 weeks ago 224 MB
centos latest dade6cb4530a 2 weeks ago 224 MB
}}}
(I made a few corrections to the dockerfile and rebuilt again, so the imageid has changed), but now we can run the container :
{{{
[root@localhost dockerfiles]# docker run -d 133f6647de58
ab3fcb88cb92d2136f8f9862176d129ad00cd121656fec7a0393b1873a45e2b4
[root@localhost dockerfiles]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab3fcb88cb92 tomcat8:latest "/bin/sh -c '/usr/lo 4 seconds ago Up 3 seconds clever_brattain
}}}
Now what is the IP address of this container , we can find that out by running a command in the already running container :
{{{
[root@localhost dockerfiles]# docker exec -t ab3fcb88cb92 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
48: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 02:42:ac:11:00:18 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.24/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:18/64 scope link
valid_lft forever preferred_lft forever
}}}
!!! Docker management tools
* [projectatomic|http://www.projectatomic.io]
* [panamax|http://panamax.io/]
* [mist.io|https://github.com/mistio/mist.io]
!! Panamax
{{{
███████╗ ██████╗ █████████╗ ██████╗ ██████████╗ ██████╗ ██╗ ██╗
██╔══██║ ╚═══██╗ ███╗ ███║ ╚═══██╗ ██║ ██╔ ██║ ╚═══██╗ ╚██╗██╔╝
██ ██║ ███████║ ███║ ███║ ███████║ ██║╚██║ ██║ ███████║ ╚███╔╝
███████╝ ███████║ ███║ ███║ ███████║ ██║╚██║ ██║ ███████║ ██╔██╗
██║ ███████║ ███║ ███║ ███████║ ██║╚██║ ██║ ███████║ ██╔╝ ██╗
╚═╝ ╚══════╝ ╚══╝ ╚══╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝
CenturyLink Labs - http://www.centurylinklabs.com/
Checking if required software is installed.
Vagrant 1.6 or newer installed.
Virtualbox 4.3 or newer installed.
Creating a new CoreOS VM...
UUID changed to: db487bd4-a551-438c-ac36-86ce9bafac9a
Bringing machine 'panamax-vm' up with 'virtualbox' provider...
==> panamax-vm: Importing base box 'panamax-coreos-box-522.6.0'...
==> panamax-vm: Matching MAC address for NAT networking...
==> panamax-vm: Setting the name of the VM: panamax-vm
==> panamax-vm: Clearing any previously set network interfaces...
The specified host network collides with a non-hostonly network!
This will cause your specified IP to be inaccessible. Please change
the IP or name of your host only network so that it no longer matches that of
a bridged or non-hostonly network.
VM Creation failed. Exiting.
metskem@athena:~$
}}}