Docker Hello World Example

Some quick notes on how to get up and running with Docker.

Installation

On Fedora this turned out to be pretty easy, simply:

dnf install docker

For other systems see the Docker installation manual.

Start docker demon

systemctl status -l docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2015-12-12 22:40:41 GMT; 3min 35s ago
Docs: http://docs.docker.com
Main PID: 5818 (docker)
CGroup: /system.slice/docker.service
└─5818 /usr/bin/docker daemon --selinux-enabled

Dec 12 22:40:01 asterix docker[5818]: time="2015-12-12T22:40:01.803909914Z" level=error msg="WARNING: No --storage-opt dm.thinpooldev specified, using loopback; this configuration is strongly discouraged for production use"
Dec 12 22:40:40 asterix docker[5818]: time="2015-12-12T22:40:39.995085846Z" level=warning msg="Docker could not enable SELinux on the host system"
Dec 12 22:40:40 asterix docker[5818]: time="2015-12-12T22:40:40.059743984Z" level=info msg="Option DefaultDriver: bridge"
Dec 12 22:40:40 asterix docker[5818]: time="2015-12-12T22:40:40.059788786Z" level=info msg="Option DefaultNetwork: bridge"
Dec 12 22:40:40 asterix docker[5818]: time="2015-12-12T22:40:40.388329409Z" level=info msg="Firewalld running: true"
Dec 12 22:40:41 asterix docker[5818]: time="2015-12-12T22:40:41.278276562Z" level=info msg="Loading containers: start."
Dec 12 22:40:41 asterix docker[5818]: time="2015-12-12T22:40:41.278585203Z" level=info msg="Loading containers: done."
Dec 12 22:40:41 asterix docker[5818]: time="2015-12-12T22:40:41.278606222Z" level=info msg="Daemon has completed initialization"
Dec 12 22:40:41 asterix docker[5818]: time="2015-12-12T22:40:41.278627443Z" level=info msg="Docker daemon" commit="cb216be/1.8.2" execdriver=native-0.2 graphdriver=devicemapper version=1.8.2-fc22
Dec 12 22:40:41 asterix systemd[1]: Started Docker Application Container Engine.

An interesting warning about no –storage-opt db.thinpooldev specified. This is related to Docker’s storage driver, which the docs explain in good detail.

Run Hello World

First, some info about the docker installation

docker info

It’s better to follow along the official and pretty good step by step documentation on basic docker usage, but the basics are below:

Run a single command

[root@asterix ~]# docker run ubuntu:14.04 /bin/echo 'Hello world'
Hello world

Interactive shell

[root@asterix ~]# docker run -t -i ubuntu:14.04 /bin/bash
root@8aed75e824e2:/# hostname
8aed75e824e2
root@8aed75e824e2:/# exit
exit
[root@asterix ~]#

Restart a container that was previously running

docker ps -a
docker restart $CONTAINER_ID
docker exec -it $CONTAINER_ID /bin/bash

Copy file from container to host

docker cp $CONTAINER_ID:$CONTAINER_PATH $HOST_PATH

Under the covers

Basic information about the newly created image:

[root@asterix ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker.io/ubuntu 14.04 d55e68e6cc9c 4 days ago 187.9 MB

Local docker containers are stored in /var/lib/docker

[root@asterix ~]# ls -l /var/lib/docker/
total 36
drwx------ 5 root root 4096 Dec 12 23:09 containers
drwx------ 5 root root 4096 Dec 12 22:50 devicemapper
drwx------ 7 root root 4096 Dec 12 22:50 graph
-rw-r--r-- 1 root root 5120 Dec 12 23:09 linkgraph.db
-rw------- 1 root root 114 Dec 12 22:50 repositories-devicemapper
drwx------ 2 root root 4096 Dec 12 22:50 tmp
drwx------ 2 root root 4096 Dec 12 22:49 trust
drwx------ 2 root root 4096 Dec 12 22:40 volumes

And we can see what looks like a ext4 filesystem:

[root@asterix ~]# file /var/lib/docker/devicemapper/devicemapper/data
/var/lib/docker/devicemapper/devicemapper/data: Linux rev 1.0 ext4 filesystem data, UUID=6d11e0b5-f063-4a4f-99f4-36253b12b297 (extents) (large files) (huge files)
Docker Hello World Example

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s