Docker#
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/bashYou 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
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
todo #
- how do I bootstrap the container, for example start nginx on start of the container ?
