I use this notebook to learn the basic usage of Docker & Vagrant.


28.11.2016

Let's first take a look of the usage of some commands:

docker run

!docker run -it ubuntu /bin/bash

remark: -i:interactive;

-t:tty(teletypewriter, i.e. text-only console)


In [ ]:
instead running an interactive shell, one can initiaa

exercise: keep printing hello world before the termination of the daemon:


In [7]:
!docker run --name daemon-dyson -d ubuntu /bin/bash -c "while true; do echo hello world;sleep 1;done"


152403910c2dd62bb641237af736266131625802cc1cac78711183cf8bcf376d

remark: -d:daemon; -c:commands

docker ps


In [8]:
!docker ps -a


CONTAINER ID        IMAGE               COMMAND                   CREATED              STATUS                      PORTS               NAMES
152403910c2d        ubuntu              "/bin/bash -c 'while "    8 seconds ago        Up 8 seconds                                    daemon-dyson
f5d0f894cc1b        ubuntu              "/bin/bash -c 'while "    About a minute ago   Up About a minute                               daemon-dave
c9d2c30b0fb3        ubuntu              "/bash -c '\nwhile tru"   2 minutes ago        Created                                         daemon-david
e1f42ce9564d        ubuntu              "/bin/bash"               15 minutes ago       Exited (0) 12 minutes ago                       thirsty_kirch
b865e0258c70        ubuntu              "/bin/bash"               16 minutes ago       Exited (0) 15 minutes ago                       lonely_brahmagupta
79b730a57076        ubuntu              "/bin/bash"               16 minutes ago       Exited (0) 16 minutes ago                       hungry_ritchie
9f4e78018f4f        ubuntu              "/bin/bash"               About an hour ago    Exited (0) 19 minutes ago                       wengsubuntu
4d9c9c79fe36        ubuntu              "/bin/bash"               2 hours ago          Exited (0) 16 minutes ago                       modest_bartik
5d64fa1d694b        hello-world         "/hello"                  3 hours ago          Exited (0) 3 hours ago                          lonely_stallman

docker logs


In [9]:
!docker logs daemon-dyson


hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world

In [12]:
!docker logs -t --tail 10 daemon-dyson


2016-11-28T05:52:44.097906219Z hello world
2016-11-28T05:52:45.144575564Z hello world
2016-11-28T05:52:46.148157811Z hello world
2016-11-28T05:52:47.150192084Z hello world
2016-11-28T05:52:48.154457162Z hello world
2016-11-28T05:52:49.158635012Z hello world
2016-11-28T05:52:50.163771180Z hello world
2016-11-28T05:52:51.174407752Z hello world
2016-11-28T05:52:52.182774174Z hello world
2016-11-28T05:52:53.186520435Z hello world

In [ ]:
!docker logs -t -f daemon-dyson

the flag -f will keep refreshing the log file.


In [13]:
!docker top daemon-dyson


PID                 USER                COMMAND
17362               root                /bin/bash -c while true; do echo hello world;sleep 1;done
18380               root                sleep 1

In [ ]:
showing the last three processes:

In [2]:
!docker ps -n 3


CONTAINER ID        IMAGE               COMMAND                   CREATED             STATUS              PORTS               NAMES
152403910c2d        ubuntu              "/bin/bash -c 'while "    34 minutes ago      Up 34 minutes                           daemon-dyson
f5d0f894cc1b        ubuntu              "/bin/bash -c 'while "    35 minutes ago      Up 35 minutes                           daemon-dave
c9d2c30b0fb3        ubuntu              "/bash -c '\nwhile tru"   36 minutes ago      Created                                 daemon-david

docker attach

(attach to a running container)

!docker attach daemon-dyson

docker inspect

inspect the selected container:


In [8]:
!docker inspect daemon-dyson


[
    {
        "Id": "152403910c2dd62bb641237af736266131625802cc1cac78711183cf8bcf376d",
        "Created": "2016-11-28T05:48:01.033944249Z",
        "Path": "/bin/bash",
        "Args": [
            "-c",
            "while true; do echo hello world;sleep 1;done"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 17362,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-11-28T05:48:01.126423857Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:e4415b714b624040f19f45994b51daed5cbdb00e0eb9a07221ff0bd6bcf55ed7",
        "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/152403910c2dd62bb641237af736266131625802cc1cac78711183cf8bcf376d/resolv.conf",
        "HostnamePath": "/mnt/sda1/var/lib/docker/containers/152403910c2dd62bb641237af736266131625802cc1cac78711183cf8bcf376d/hostname",
        "HostsPath": "/mnt/sda1/var/lib/docker/containers/152403910c2dd62bb641237af736266131625802cc1cac78711183cf8bcf376d/hosts",
        "LogPath": "/mnt/sda1/var/lib/docker/containers/152403910c2dd62bb641237af736266131625802cc1cac78711183cf8bcf376d/152403910c2dd62bb641237af736266131625802cc1cac78711183cf8bcf376d-json.log",
        "Name": "/daemon-dyson",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [],
        "Config": {
            "Hostname": "152403910c2d",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash",
                "-c",
                "while true; do echo hello world;sleep 1;done"
            ],
            "Image": "ubuntu",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "16134da9abdda0e82958e8ce863bfbbcdf33589177bd90c52509648d345353a9",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/16134da9abdd",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "50f4214b2c70ea7ea6bf372444eb595ea7da7f752d8a11cf59156eb2a5bae7db",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "03569ac3ef89ba2e486a07293c37e71fd931a2a5c865b2f437be82c18f1bbe61",
                    "EndpointID": "50f4214b2c70ea7ea6bf372444eb595ea7da7f752d8a11cf59156eb2a5bae7db",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03"
                }
            }
        }
    }
]

extract some info from the command docker inspect:


In [19]:
%%bash

docker inspect --format="{{.State.Running}}" daemon-dyson


true

In [18]:
%%bash

docker inspect --format="{{.NetworkSettings.IPAddress}}" daemon-dyson


172.17.0.3

the -A flag of grep:

(-A: afterwards)


In [27]:
%%bash

docker inspect daemon-dyson |grep -A 100 "NetworkSettings"


        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "16134da9abdda0e82958e8ce863bfbbcdf33589177bd90c52509648d345353a9",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/16134da9abdd",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "50f4214b2c70ea7ea6bf372444eb595ea7da7f752d8a11cf59156eb2a5bae7db",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "03569ac3ef89ba2e486a07293c37e71fd931a2a5c865b2f437be82c18f1bbe61",
                    "EndpointID": "50f4214b2c70ea7ea6bf372444eb595ea7da7f752d8a11cf59156eb2a5bae7db",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03"
                }
            }
        }
    }
]

stop and remove a daemon:


In [28]:
%%bash
docker stop daemon-dave
docker rm daemon-dave


daemon-dave

In [32]:
%%bash
docker ps -a


CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS               NAMES
152403910c2d        ubuntu              "/bin/bash -c 'while "   53 minutes ago      Up 53 minutes                                      daemon-dyson
e1f42ce9564d        ubuntu              "/bin/bash"              About an hour ago   Exited (0) About an hour ago                       thirsty_kirch
b865e0258c70        ubuntu              "/bin/bash"              About an hour ago   Exited (0) About an hour ago                       lonely_brahmagupta
79b730a57076        ubuntu              "/bin/bash"              About an hour ago   Exited (0) About an hour ago                       hungry_ritchie
9f4e78018f4f        ubuntu              "/bin/bash"              2 hours ago         Exited (0) About an hour ago                       wengsubuntu
4d9c9c79fe36        ubuntu              "/bin/bash"              3 hours ago         Exited (0) About an hour ago                       modest_bartik
5d64fa1d694b        hello-world         "/hello"                 4 hours ago         Exited (0) 4 hours ago                             lonely_stallman

In [33]:
!docker images


REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              e4415b714b62        11 days ago         128.1 MB
hello-world         latest              c54a2cc56cbb        4 months ago        1.848 kB

In [35]:
!docker search ubuntu


NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                            Ubuntu is a Debian-based Linux operating s...   5110      [OK]       
ubuntu-upstart                    Upstart is an event-based replacement for ...   69        [OK]       
rastasheep/ubuntu-sshd            Dockerized SSH service, built on top of of...   53                   [OK]
consol/ubuntu-xfce-vnc            Ubuntu container with "headless" VNC sessi...   32                   [OK]
ubuntu-debootstrap                debootstrap --variant=minbase --components...   27        [OK]       
torusware/speedus-ubuntu          Always updated official Ubuntu docker imag...   27                   [OK]
ioft/armhf-ubuntu                 [ABR] Ubuntu Docker images for the ARMv7(a...   19                   [OK]
nuagebec/ubuntu                   Simple always updated Ubuntu docker images...   11                   [OK]
nickistre/ubuntu-lamp             LAMP server on Ubuntu                           11                   [OK]
nickistre/ubuntu-lamp-wordpress   LAMP on Ubuntu with wp-cli installed            7                    [OK]
nimmis/ubuntu                     This is a docker images different LTS vers...   5                    [OK]
maxexcloo/ubuntu                  Base image built on Ubuntu with init, Supe...   2                    [OK]
admiringworm/ubuntu               Base ubuntu images based on the official u...   1                    [OK]
darksheer/ubuntu                  Base Ubuntu Image -- Updated hourly             1                    [OK]
jordi/ubuntu                      Ubuntu Base Image                               1                    [OK]
lynxtp/ubuntu                     https://github.com/lynxtp/docker-ubuntu         0                    [OK]
teamrock/ubuntu                   TeamRock's Ubuntu image configured with AW...   0                    [OK]
vcatechnology/ubuntu              A Ubuntu image that is updated daily            0                    [OK]
labengine/ubuntu                  Images base ubuntu                              0                    [OK]
widerplan/ubuntu                  Our basic Ubuntu images.                        0                    [OK]
esycat/ubuntu                     Ubuntu LTS                                      0                    [OK]
ustclug/ubuntu                    ubuntu image for docker with USTC mirror        0                    [OK]
webhippie/ubuntu                  Docker images for ubuntu                        0                    [OK]
konstruktoid/ubuntu               Ubuntu base image                               0                    [OK]
datenbetrieb/ubuntu               custom flavor of the official ubuntu base ...   0                    [OK]

In [37]:
!docker search dafu


NAME                  DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
dafu/worker                                                           1                    
dafu/bigdata          Big Data ecosystem : Base System (Ubuntu 1...   1                    
dafu/dkutil           Docker utilities for Hadoop Ecosystem           0                    
dafu/hadoop           Hadoop ���蝟餌絞憟�辣                                   0                    
dafu/myweb            zzzzzz                                          0                    
dafu/appstore         Application Container                           0                    
dafu/mybase           撌脣���OpenSSh, �航�閮�IP 雿��                          0                    
dafu/busybox          �芷���� Busybox image                              0                    
dafu/mysql                                                            0                    
dafu/bigboss                                                          0                    
dafu/chtbase          銝剛��颱縑撠�� - 撌脰身摰�Proxy                              0                    
dafu/myjava                                                           0                    
dafu/zzzz                                                             0                    
dafu/mynginx                                                          0                    
dafuni/docker-whale                                                   0                    

In [40]:
%%bash
docker search busybox


NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
busybox                         Busybox base image.                             861       [OK]       
progrium/busybox                                                                65                   [OK]
radial/busyboxplus              Full-chain, Internet enabled, busybox made...   11                   [OK]
odise/busybox-python                                                            4                    [OK]
sequenceiq/busybox                                                              2                    [OK]
container4armhf/armhf-busybox   Automated build of Busybox for armhf devic...   2                    [OK]
multiarch/busybox               multiarch ports of ubuntu-debootstrap           2                    [OK]
azukiapp/busybox                This image is meant to be used as the base...   2                    [OK]
odise/busybox-curl                                                              1                    [OK]
elektritter/busybox-teamspeak   Leightweight teamspeak3 container based on...   1                    [OK]
ofayau/busybox-libc32           Busybox with 32 bits (and 64 bits) libs         1                    [OK]
getblank/busybox                Docker container busybox for Blank              1                    [OK]
socketplane/busybox                                                             1                    [OK]
skomma/busybox-data             Docker image suitable for data volume cont...   1                    [OK]
ofayau/busybox-jvm              Prepare busybox to install a 32 bits JVM.       1                    [OK]
freenas/busybox                 Busybox image enhanced with FreeNAS 10 met...   0                    [OK]
jahroots/busybox                Busybox containers                              0                    [OK]
ddn0/busybox                    fork of official busybox                        0                    [OK]
futurenda/busybox               Mini busybox                                    0                    [OK]
ggtools/busybox-ubuntu          Busybox ubuntu version with extra goodies       0                    [OK]
sdurrheimer/prom-busybox        Moved to https://hub.docker.com/r/prom/bus...   0                    [OK]
cucy/busybox                    aouto  build busybox                            0                    [OK]
oveits/docker-nginx-busybox     This is a tiny NginX docker image based on...   0                    [OK]
prom/busybox                    Prometheus Busybox Docker base images           0                    [OK]
nikfoundas/busybox-confd        Minimal busybox based distribution of confd     0                    [OK]

In [42]:
%%bash
docker pull busybox


Using default tag: latest
latest: Pulling from library/busybox
56bec22e3559: Pulling fs layer
56bec22e3559: Verifying Checksum
56bec22e3559: Download complete
56bec22e3559: Pull complete
Digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912
Status: Downloaded newer image for busybox:latest

In [51]:
!docker history ubuntu


IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
e4415b714b62        11 days ago         /bin/sh -c #(nop)  CMD ["/bin/bash"]            0 B                 
<missing>           11 days ago         /bin/sh -c mkdir -p /run/systemd && echo 'doc   7 B                 
<missing>           11 days ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.895 kB            
<missing>           11 days ago         /bin/sh -c rm -rf /var/lib/apt/lists/*          0 B                 
<missing>           11 days ago         /bin/sh -c set -xe   && echo '#!/bin/sh' > /u   745 B               
<missing>           11 days ago         /bin/sh -c #(nop) ADD file:abc033900893f6c737   128.1 MB            

In [ ]:
$docker rm $(docker ps -a -q)

In [69]:
for name in ["daemon-dyson","thirsty_kirch","lonely_brahmagupta","hungry_ritchie","modest_bartik","lonely_stallman"]:
    !docker rm {name}
    
!docker ps -a


daemon-dyson
thirsty_kirch
lonely_brahmagupta
hungry_ritchie
modest_bartik
lonely_stallman
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
9f4e78018f4f        ubuntu              "/bin/bash"         4 hours ago         Exited (0) 3 hours ago                       wengsubuntu

About Docker Image:

check http://imagelayers.io/ or https://microbadger.com/images/ for some further details of a specific image of layers.

build a docker image

we add some layers to the base image ubuntu:

# Version: 0.0.1
FROM ubuntu
MAINTAINER CHWENG "CHWENG@example.com"

# Avoid ERROR: invoke-rc.d: policy-rc.d denied execution of start.
#RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
RUN apt-get update
RUN apt-get install -y nginx
RUN echo 'Hi, I am in the container' \
    >/var/www/html/index.html
    #>/usr/share/nginx/html/index.html

CMD [ "nginx", "-g", "daemon off;" ]EXPOSE 80

In [73]:
%%bash
cd static_web/
ls
docker build -t "iiiedu/static_web" .


Dockerfile

Step 1 : FROM ubuntu
 ---> e4415b714b62
Step 2 : MAINTAINER iii education "iiiedu@example.com"
 ---> Running in dab2fd506966
 ---> e934c26893ec
Removing intermediate container dab2fd506966
Step 3 : RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
 ---> Running in 5f68c50b32d3
 ---> b1e806d92b03
Removing intermediate container 5f68c50b32d3
Step 4 : RUN apt-get update
 ---> Running in 3a85f8b55ba4
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial/main Sources [1103 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/restricted Sources [5179 B]
Get:6 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main Sources [259 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial-updates/restricted Sources [1872 B]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [137 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [543 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [11.7 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [458 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-security/main Sources [58.9 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-security/restricted Sources [1872 B]
Get:18 http://archive.ubuntu.com/ubuntu xenial-security/universe Sources [15.8 kB]
Get:19 http://archive.ubuntu.com/ubuntu xenial-security/main amd64 Packages [220 kB]
Get:20 http://archive.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [11.7 kB]
Get:21 http://archive.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [75.1 kB]
Fetched 24.6 MB in 4min 33s (89.9 kB/s)
Reading package lists...
 ---> 0a196d9da1d3
Removing intermediate container 3a85f8b55ba4
Step 5 : RUN apt-get install -y nginx
 ---> Running in 8eb793283270
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core geoip-database libexpat1 libfontconfig1
  libfreetype6 libgd3 libgeoip1 libicu55 libjbig0 libjpeg-turbo8 libjpeg8
  libpng12-0 libssl1.0.0 libtiff5 libvpx3 libx11-6 libx11-data libxau6 libxcb1
  libxdmcp6 libxml2 libxpm4 libxslt1.1 nginx-common nginx-core sgml-base ucf
  xml-core
Suggested packages:
  libgd-tools geoip-bin fcgiwrap nginx-doc ssl-cert sgml-base-doc debhelper
The following NEW packages will be installed:
  fontconfig-config fonts-dejavu-core geoip-database libexpat1 libfontconfig1
  libfreetype6 libgd3 libgeoip1 libicu55 libjbig0 libjpeg-turbo8 libjpeg8
  libpng12-0 libssl1.0.0 libtiff5 libvpx3 libx11-6 libx11-data libxau6 libxcb1
  libxdmcp6 libxml2 libxpm4 libxslt1.1 nginx nginx-common nginx-core sgml-base
  ucf xml-core
0 upgraded, 30 newly installed, 0 to remove and 3 not upgraded.
Need to get 15.5 MB of archives.
After this operation, 57.4 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxau6 amd64 1:1.0.8-1 [8376 B]
Get:2 http://archive.ubuntu.com/ubuntu xenial/main amd64 sgml-base all 1.26+nmu4ubuntu1 [12.5 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjpeg-turbo8 amd64 1.4.2-0ubuntu3 [111 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxdmcp6 amd64 1:1.1.2-1.1 [11.0 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxcb1 amd64 1.11.1-1ubuntu1 [40.0 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 libx11-data all 2:1.6.3-1ubuntu2 [113 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/main amd64 libx11-6 amd64 2:1.6.3-1ubuntu2 [571 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxpm4 amd64 1:3.5.11-1 [33.1 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjbig0 amd64 2.1-3.1 [26.6 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libexpat1 amd64 2.1.0-7ubuntu0.16.04.2 [71.3 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 libpng12-0 amd64 1.2.54-1ubuntu1 [116 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.5 [1082 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial/main amd64 ucf all 3.0036 [52.9 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial/main amd64 geoip-database all 20160408-1 [1678 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial/main amd64 libgeoip1 amd64 1.6.9-1 [70.1 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial/main amd64 libicu55 amd64 55.1-7 [7643 kB]
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libxml2 amd64 2.9.3+dfsg1-1ubuntu0.1 [696 kB]
Get:18 http://archive.ubuntu.com/ubuntu xenial/main amd64 xml-core all 0.13+nmu2 [23.3 kB]
Get:19 http://archive.ubuntu.com/ubuntu xenial/main amd64 fonts-dejavu-core all 2.35-1 [1039 kB]
Get:20 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 fontconfig-config all 2.11.94-0ubuntu1.1 [49.9 kB]
Get:21 http://archive.ubuntu.com/ubuntu xenial/main amd64 libfreetype6 amd64 2.6.1-0.1ubuntu2 [316 kB]
Get:22 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libfontconfig1 amd64 2.11.94-0ubuntu1.1 [131 kB]
Get:23 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjpeg8 amd64 8c-2ubuntu8 [2194 B]
Get:24 http://archive.ubuntu.com/ubuntu xenial/main amd64 libtiff5 amd64 4.0.6-1 [144 kB]
Get:25 http://archive.ubuntu.com/ubuntu xenial/main amd64 libvpx3 amd64 1.5.0-2ubuntu1 [732 kB]
Get:26 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libgd3 amd64 2.1.1-4ubuntu0.16.04.5 [125 kB]
Get:27 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxslt1.1 amd64 1.1.28-2.1 [145 kB]
Get:28 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-common all 1.10.0-0ubuntu0.16.04.4 [26.6 kB]
Get:29 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-core amd64 1.10.0-0ubuntu0.16.04.4 [428 kB]
Get:30 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx all 1.10.0-0ubuntu0.16.04.4 [3498 B]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 15.5 MB in 2min 17s (113 kB/s)
Selecting previously unselected package libxau6:amd64.
(Reading database ... 7259 files and directories currently installed.)
Preparing to unpack .../libxau6_1%3a1.0.8-1_amd64.deb ...
Unpacking libxau6:amd64 (1:1.0.8-1) ...
Selecting previously unselected package sgml-base.
Preparing to unpack .../sgml-base_1.26+nmu4ubuntu1_all.deb ...
Unpacking sgml-base (1.26+nmu4ubuntu1) ...
Selecting previously unselected package libjpeg-turbo8:amd64.
Preparing to unpack .../libjpeg-turbo8_1.4.2-0ubuntu3_amd64.deb ...
Unpacking libjpeg-turbo8:amd64 (1.4.2-0ubuntu3) ...
Selecting previously unselected package libxdmcp6:amd64.
Preparing to unpack .../libxdmcp6_1%3a1.1.2-1.1_amd64.deb ...
Unpacking libxdmcp6:amd64 (1:1.1.2-1.1) ...
Selecting previously unselected package libxcb1:amd64.
Preparing to unpack .../libxcb1_1.11.1-1ubuntu1_amd64.deb ...
Unpacking libxcb1:amd64 (1.11.1-1ubuntu1) ...
Selecting previously unselected package libx11-data.
Preparing to unpack .../libx11-data_2%3a1.6.3-1ubuntu2_all.deb ...
Unpacking libx11-data (2:1.6.3-1ubuntu2) ...
Selecting previously unselected package libx11-6:amd64.
Preparing to unpack .../libx11-6_2%3a1.6.3-1ubuntu2_amd64.deb ...
Unpacking libx11-6:amd64 (2:1.6.3-1ubuntu2) ...
Selecting previously unselected package libxpm4:amd64.
Preparing to unpack .../libxpm4_1%3a3.5.11-1_amd64.deb ...
Unpacking libxpm4:amd64 (1:3.5.11-1) ...
Selecting previously unselected package libjbig0:amd64.
Preparing to unpack .../libjbig0_2.1-3.1_amd64.deb ...
Unpacking libjbig0:amd64 (2.1-3.1) ...
Selecting previously unselected package libexpat1:amd64.
Preparing to unpack .../libexpat1_2.1.0-7ubuntu0.16.04.2_amd64.deb ...
Unpacking libexpat1:amd64 (2.1.0-7ubuntu0.16.04.2) ...
Selecting previously unselected package libpng12-0:amd64.
Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1_amd64.deb ...
Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1) ...
Selecting previously unselected package libssl1.0.0:amd64.
Preparing to unpack .../libssl1.0.0_1.0.2g-1ubuntu4.5_amd64.deb ...
Unpacking libssl1.0.0:amd64 (1.0.2g-1ubuntu4.5) ...
Selecting previously unselected package ucf.
Preparing to unpack .../archives/ucf_3.0036_all.deb ...
Moving old data out of the way
Unpacking ucf (3.0036) ...
Selecting previously unselected package geoip-database.
Preparing to unpack .../geoip-database_20160408-1_all.deb ...
Unpacking geoip-database (20160408-1) ...
Selecting previously unselected package libgeoip1:amd64.
Preparing to unpack .../libgeoip1_1.6.9-1_amd64.deb ...
Unpacking libgeoip1:amd64 (1.6.9-1) ...
Selecting previously unselected package libicu55:amd64.
Preparing to unpack .../libicu55_55.1-7_amd64.deb ...
Unpacking libicu55:amd64 (55.1-7) ...
Selecting previously unselected package libxml2:amd64.
Preparing to unpack .../libxml2_2.9.3+dfsg1-1ubuntu0.1_amd64.deb ...
Unpacking libxml2:amd64 (2.9.3+dfsg1-1ubuntu0.1) ...
Selecting previously unselected package xml-core.
Preparing to unpack .../xml-core_0.13+nmu2_all.deb ...
Unpacking xml-core (0.13+nmu2) ...
Selecting previously unselected package fonts-dejavu-core.
Preparing to unpack .../fonts-dejavu-core_2.35-1_all.deb ...
Unpacking fonts-dejavu-core (2.35-1) ...
Selecting previously unselected package fontconfig-config.
Preparing to unpack .../fontconfig-config_2.11.94-0ubuntu1.1_all.deb ...
Unpacking fontconfig-config (2.11.94-0ubuntu1.1) ...
Selecting previously unselected package libfreetype6:amd64.
Preparing to unpack .../libfreetype6_2.6.1-0.1ubuntu2_amd64.deb ...
Unpacking libfreetype6:amd64 (2.6.1-0.1ubuntu2) ...
Selecting previously unselected package libfontconfig1:amd64.
Preparing to unpack .../libfontconfig1_2.11.94-0ubuntu1.1_amd64.deb ...
Unpacking libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
Selecting previously unselected package libjpeg8:amd64.
Preparing to unpack .../libjpeg8_8c-2ubuntu8_amd64.deb ...
Unpacking libjpeg8:amd64 (8c-2ubuntu8) ...
Selecting previously unselected package libtiff5:amd64.
Preparing to unpack .../libtiff5_4.0.6-1_amd64.deb ...
Unpacking libtiff5:amd64 (4.0.6-1) ...
Selecting previously unselected package libvpx3:amd64.
Preparing to unpack .../libvpx3_1.5.0-2ubuntu1_amd64.deb ...
Unpacking libvpx3:amd64 (1.5.0-2ubuntu1) ...
Selecting previously unselected package libgd3:amd64.
Preparing to unpack .../libgd3_2.1.1-4ubuntu0.16.04.5_amd64.deb ...
Unpacking libgd3:amd64 (2.1.1-4ubuntu0.16.04.5) ...
Selecting previously unselected package libxslt1.1:amd64.
Preparing to unpack .../libxslt1.1_1.1.28-2.1_amd64.deb ...
Unpacking libxslt1.1:amd64 (1.1.28-2.1) ...
Selecting previously unselected package nginx-common.
Preparing to unpack .../nginx-common_1.10.0-0ubuntu0.16.04.4_all.deb ...
Unpacking nginx-common (1.10.0-0ubuntu0.16.04.4) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../nginx-core_1.10.0-0ubuntu0.16.04.4_amd64.deb ...
Unpacking nginx-core (1.10.0-0ubuntu0.16.04.4) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.10.0-0ubuntu0.16.04.4_all.deb ...
Unpacking nginx (1.10.0-0ubuntu0.16.04.4) ...
Processing triggers for libc-bin (2.23-0ubuntu4) ...
Processing triggers for systemd (229-4ubuntu12) ...
Setting up libxau6:amd64 (1:1.0.8-1) ...
Setting up sgml-base (1.26+nmu4ubuntu1) ...
Setting up libjpeg-turbo8:amd64 (1.4.2-0ubuntu3) ...
Setting up libxdmcp6:amd64 (1:1.1.2-1.1) ...
Setting up libxcb1:amd64 (1.11.1-1ubuntu1) ...
Setting up libx11-data (2:1.6.3-1ubuntu2) ...
Setting up libx11-6:amd64 (2:1.6.3-1ubuntu2) ...
Setting up libxpm4:amd64 (1:3.5.11-1) ...
Setting up libjbig0:amd64 (2.1-3.1) ...
Setting up libexpat1:amd64 (2.1.0-7ubuntu0.16.04.2) ...
Setting up libpng12-0:amd64 (1.2.54-1ubuntu1) ...
Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu4.5) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up ucf (3.0036) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up geoip-database (20160408-1) ...
Setting up libgeoip1:amd64 (1.6.9-1) ...
Setting up libicu55:amd64 (55.1-7) ...
Setting up libxml2:amd64 (2.9.3+dfsg1-1ubuntu0.1) ...
Setting up xml-core (0.13+nmu2) ...
Setting up fonts-dejavu-core (2.35-1) ...
Setting up fontconfig-config (2.11.94-0ubuntu1.1) ...
Setting up libfreetype6:amd64 (2.6.1-0.1ubuntu2) ...
Setting up libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
Setting up libjpeg8:amd64 (8c-2ubuntu8) ...
Setting up libtiff5:amd64 (4.0.6-1) ...
Setting up libvpx3:amd64 (1.5.0-2ubuntu1) ...
Setting up libgd3:amd64 (2.1.1-4ubuntu0.16.04.5) ...
Setting up libxslt1.1:amd64 (1.1.28-2.1) ...
Setting up nginx-common (1.10.0-0ubuntu0.16.04.4) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up nginx-core (1.10.0-0ubuntu0.16.04.4) ...
invoke-rc.d: could not determine current runlevel
 * Starting nginx nginx
   ...done.
Setting up nginx (1.10.0-0ubuntu0.16.04.4) ...
Processing triggers for libc-bin (2.23-0ubuntu4) ...
Processing triggers for sgml-base (1.26+nmu4ubuntu1) ...
Processing triggers for systemd (229-4ubuntu12) ...
 ---> 0328f15773dd
Removing intermediate container 8eb793283270
Step 6 : RUN echo 'Hi, I am in your container'     >/usr/share/nginx/html/index.html
 ---> Running in c16634018e43
 ---> c140d579f8e9
Removing intermediate container c16634018e43
Step 7 : CMD nginx -g daemon off;
 ---> Running in 272f90adaf95
 ---> 9626cc135a4f
Removing intermediate container 272f90adaf95
Successfully built 9626cc135a4f
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

In [75]:
%%bash
docker images


REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
iiiedu/static_web   latest              9626cc135a4f        40 seconds ago      224.3 MB
ubuntu              latest              e4415b714b62        11 days ago         128.1 MB
busybox             latest              e02e811dd08f        7 weeks ago         1.093 MB
hello-world         latest              c54a2cc56cbb        4 months ago        1.848 kB

In [76]:
%%bash
docker history iiiedu/static_web


IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
9626cc135a4f        4 minutes ago       /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon    0 B                 
c140d579f8e9        4 minutes ago       /bin/sh -c echo 'Hi, I am in your container'    27 B                
0328f15773dd        4 minutes ago       /bin/sh -c apt-get install -y nginx             56.82 MB            
0a196d9da1d3        6 minutes ago       /bin/sh -c apt-get update                       39.36 MB            
b1e806d92b03        11 minutes ago      /bin/sh -c echo "#!/bin/sh\nexit 0" > /usr/sb   17 B                
e934c26893ec        11 minutes ago      /bin/sh -c #(nop)  MAINTAINER iii education "   0 B                 
e4415b714b62        11 days ago         /bin/sh -c #(nop)  CMD ["/bin/bash"]            0 B                 
<missing>           11 days ago         /bin/sh -c mkdir -p /run/systemd && echo 'doc   7 B                 
<missing>           11 days ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.895 kB            
<missing>           11 days ago         /bin/sh -c rm -rf /var/lib/apt/lists/*          0 B                 
<missing>           11 days ago         /bin/sh -c set -xe   && echo '#!/bin/sh' > /u   745 B               
<missing>           11 days ago         /bin/sh -c #(nop) ADD file:abc033900893f6c737   128.1 MB            

In [77]:
%%bash
docker run -d -p 80 --name static_web iiiedu/static_web


7df500d5695bcb608d3b4f854605201296729a4181ee422abb17cfd7c4d0a738

In [80]:
%%bash
docker ps


CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES
7df500d5695b        iiiedu/static_web   "nginx -g 'daemon off"   18 seconds ago      Up 16 seconds       0.0.0.0:32768->80/tcp   static_web

docker exec

use docker exec in order to access to an interactive terminal of the daemonized container (since if we use docker attach, we'll obtain a running terminal, which is not convenient if we'd like to do some extra things interactively.)

docker exec -it static_web /bin/bash

to look for the location of the html file generated by nginx:

root@7df500d5695b:/# find . -name "*.html"
./var/www/html/index.nginx-debian.html
./usr/share/nginx/html/index.html
./usr/share/doc/libfreetype6/ft2faq.html
./usr/share/doc/base-passwd/users-and-groups.html
./usr/share/doc/adduser/examples/adduser.local.conf.examples/skel.other/index.html
docker exec -t stat /bin/ps
  PID TTY          TIME CMD
   35 ?        00:00:00 ps

use the flag -v(volume) to share files with the container:

docker run -it -P --name web-apache -v ~/apache2/html:/var/www/html iiiedu/apache

(a volume that is going to share data with the container will be created)

exercise: run a nginx server

(the volume is mounted with the read only option)

docker run -d -p 80:80 -v /tmp/www:/usr/share/nginx/html:ro nginx

troubleshooting: env in windows

In windows 7, I met some problem while trying to access docker from BASH (MINGW64). This is fixed after following

https://github.com/docker/docker/issues/22338


In [3]:
%%bash
docker-machine env default


export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="C:\Users\admin\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell: 
# eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env default)

exercise: listen to the socket 9000


In [1]:
%%bash

docker run -d --name java_sock -p 9000:9000 -v $PWD/code:/javatest iiiedu/socket 9000


C:\Program Files\Docker Toolbox\docker.exe: An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/create?name=java_sock: open //./pipe/docker_engine: The system cannot find the file specified..
See 'C:\Program Files\Docker Toolbox\docker.exe run --help'.

tomcat


In [5]:
%%bash
docker search tomcat


NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tomcat                            Apache Tomcat is an open source implementa...   1047      [OK]       
dordoka/tomcat                    Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba...   27                   [OK]
consol/tomcat-7.0                 Tomcat 7.0.57, 8080, "admin/admin"              16                   [OK]
consol/tomcat-8.0                 Tomcat 8.0.15, 8080, "admin/admin"              15                   [OK]
cloudesire/tomcat                 Tomcat server, 6/7/8                            11                   [OK]
davidcaste/alpine-tomcat          Apache Tomcat 7/8 using Oracle Java 7/8 wi...   10                   [OK]
andreptb/tomcat                   Debian Jessie based image with Apache Tomc...   6                    [OK]
openweb/oracle-tomcat             A fork off of Official tomcat image with O...   4                    [OK]
fbrx/tomcat                       Minimal Tomcat image based on Alpine Linux      3                    [OK]
kieker/tomcat                                                                     2                    [OK]
bitnami/tomcat                    Bitnami Tomcat Docker Image                     1                    [OK]
camptocamp/tomcat-logback         Docker image for tomcat with logback integ...   1                    [OK]
picoded/tomcat                    tomcat 8 with java 8, and MANAGER_USER / M...   1                    [OK]
abzcoding/tomcat-redis            a tomcat container with redis as session m...   1                    [OK]
stakater/tomcat                   Tomcat based on Ubuntu 14.04 and Oracle Java    0                    [OK]
cheewai/tomcat                    Tomcat and Oracle JRE in docker                 0                    [OK]
charlycoste/tomcat                Debian based Tomcat (don't use it, this is...   0                    [OK]
ping2ravi/tomcat                  Tomcat Versions 7 and 8                         0                    [OK]
blueur/tomcat                     Tomcat with the possibility to set the use...   0                    [OK]
davidcaste/debian-tomcat          Yet another Debian Docker image for Tomcat...   0                    [OK]
elcom/tomcat                      Tomcat with Java                                0                    [OK]
phpmentors/tomcat-app             Tomcat application image using Maven            0                    [OK]
oriaks/tomcat                     Tomcat                                          0                    [OK]
inspectit/tomcat                  Tomcat with inspectIT                           0                    [OK]
rennergabor/virgo-tomcat-server   Docker image for Eclipse Virgo Tomcat Server    0                    [OK]

In [4]:
%%bash
docker pull tomcat:8.0


8.0: Pulling from library/tomcat
386a066cd84a: Pulling fs layer
75ea84187083: Pulling fs layer
3e2e387eb26a: Pulling fs layer
7c6c48f4275c: Pulling fs layer
887691f35f8f: Pulling fs layer
bdd1cefebf67: Pulling fs layer
598674c5963f: Pulling fs layer
cfa880bbc1a2: Pulling fs layer
d49a2408af9c: Pulling fs layer
5d631463743b: Pulling fs layer
be0768fbba94: Pulling fs layer
7c6c48f4275c: Waiting
887691f35f8f: Waiting
bdd1cefebf67: Waiting
598674c5963f: Waiting
cfa880bbc1a2: Waiting
d49a2408af9c: Waiting
5d631463743b: Waiting
be0768fbba94: Waiting
3e2e387eb26a: Verifying Checksum
3e2e387eb26a: Download complete
7c6c48f4275c: Verifying Checksum
7c6c48f4275c: Download complete
75ea84187083: Verifying Checksum
75ea84187083: Download complete
bdd1cefebf67: Verifying Checksum
bdd1cefebf67: Download complete
598674c5963f: Verifying Checksum
598674c5963f: Download complete
cfa880bbc1a2: Verifying Checksum
cfa880bbc1a2: Download complete
d49a2408af9c: Verifying Checksum
d49a2408af9c: Download complete
5d631463743b: Verifying Checksum
5d631463743b: Download complete
be0768fbba94: Verifying Checksum
be0768fbba94: Download complete
386a066cd84a: Verifying Checksum
386a066cd84a: Download complete
386a066cd84a: Pull complete
75ea84187083: Pull complete
3e2e387eb26a: Pull complete
7c6c48f4275c: Pull complete
887691f35f8f: Verifying Checksum
887691f35f8f: Download complete
887691f35f8f: Pull complete
bdd1cefebf67: Pull complete
598674c5963f: Pull complete
cfa880bbc1a2: Pull complete
d49a2408af9c: Pull complete
5d631463743b: Pull complete
be0768fbba94: Pull complete
Digest: sha256:a2d3a9e93a3bce728ac8b5e14052911a36ea1a40ef1f9b1d8203ba88945a2e33
Status: Downloaded newer image for tomcat:8.0
docker run --rm tomcat:8.0 -P --name mytomcat

the flag --rm: remove the container after finishing the execusion

FROM tomcat:8.0
MAINTAINER iii education

USER root

RUN mkdir /usr/local/tomcat/webapps/jsptes
WORKDIR /usr/local/tomcat/webapps/jsptest

In [ ]:
docker run -d --name tomcat_jsp -p 8080:8080 -v $PWD/code:/usr/local/tomcat/webaps/jsptest iiiedu/tomcat

30.11.2016

Vagrant


In [1]:
!vagrant --help


Usage: vagrant [options] <command> [<args>]

    -v, --version                    Print the version and exit.
    -h, --help                       Print this help.

Common commands:
     box             manages boxes: installation, removal, etc.
     connect         connect to a remotely shared Vagrant environment
     destroy         stops and deletes all traces of the vagrant machine
     global-status   outputs status Vagrant environments for this user
     halt            stops the vagrant machine
     help            shows the help for a subcommand
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login           log in to HashiCorp's Atlas
     package         packages a running vagrant environment into a box
     plugin          manages plugins: install, uninstall, update, etc.
     port            displays information about guest port mappings
     powershell      connects to machine via powershell remoting
     provision       provisions the vagrant machine
     push            deploys code in this environment to a configured destination
     rdp             connects to machine via RDP
     reload          restarts vagrant machine, loads new Vagrantfile configuration
     resume          resume a suspended vagrant machine
     share           share your Vagrant environment with anyone in the world
     snapshot        manages snapshots: saving, restoring, etc.
     ssh             connects to machine via SSH
     ssh-config      outputs OpenSSH valid configuration to connect to the machine
     status          outputs status of the vagrant machine
     suspend         suspends the machine
     up              starts and provisions the vagrant environment
     version         prints current and latest Vagrant version

For help on any individual command run `vagrant COMMAND -h`

Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.

In [1]:
%%bash
cd ~/
vagrant box add iiiedu/trusty64 ubuntu-trusty64.box


==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'iiiedu/trusty64' (v0) for provider: 
    box: Unpacking necessary files from: file://C:/Users/Student/ubuntu-trusty64.box
    box: 
==> box: Successfully added box 'iiiedu/trusty64' (v0) for 'virtualbox'!

In [2]:
!vagrant box list


iiiedu/trusty64 (virtualbox, 0)
iiiedu/xenial64 (virtualbox, 0)

In [2]:
%%bash
cd ~/
mkdir demo
cd demo
vagrant init iiiedu/trusty64


`Vagrantfile` already exists in this directory. Remove it before
running `vagrant init`.

In [4]:
%%bash
cat ~/demo/Vagrantfile


# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "iiiedu/trusty64"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

In [5]:
%%bash
cd ~/demo
vagrant up


Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'iiiedu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: demo_default_1480478195274_10019
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
[default] GuestAdditions versions on your host (5.1.10) and guest (5.1.8) do not match.
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
dkms is already the newest version.
linux-headers-3.13.0-101-generic is already the newest version.
The following packages were automatically installed and are no longer required:
  acl at-spi2-core colord dconf-gsettings-backend dconf-service fontconfig
  fontconfig-config fonts-dejavu-core hicolor-icon-theme libasound2
  libasound2-data libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0
  libavahi-client3 libavahi-common-data libavahi-common3 libcairo-gobject2
  libcairo2 libcanberra-gtk3-0 libcanberra-gtk3-module libcanberra0 libcolord1
  libcolorhug1 libcups2 libdatrie1 libdconf1 libdrm-intel1 libdrm-nouveau2
  libdrm-radeon1 libexif12 libfontconfig1 libfontenc1 libgd3
  libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgl1-mesa-dri libgl1-mesa-glx
  libglapi-mesa libgphoto2-6 libgphoto2-l10n libgphoto2-port10 libgraphite2-3
  libgtk-3-0 libgtk-3-bin libgtk-3-common libgudev-1.0-0 libgusb2
  libharfbuzz0b libice6 libieee1284-3 libjasper1 libjbig0 libjpeg-turbo8
  libjpeg8 liblcms2-2 libllvm3.4 libltdl7 libnotify-bin libnotify4 libogg0
  libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpciaccess0
  libpixman-1-0 libsane libsane-common libsm6 libtdb1 libthai-data libthai0
  libtiff5 libtxc-dxtn-s2tc0 libv4l-0 libv4lconvert0 libvorbis0a
  libvorbisfile3 libvpx1 libwayland-client0 libwayland-cursor0 libx11-xcb1
  libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0
  libxcb-render0 libxcb-shm0 libxcb-sync1 libxcomposite1 libxcursor1
  libxdamage1 libxfixes3 libxfont1 libxi6 libxinerama1 libxkbcommon0
  libxkbfile1 libxmu6 libxpm4 libxrandr2 libxrender1 libxshmfence1 libxt6
  libxtst6 libxxf86vm1 notification-daemon sound-theme-freedesktop x11-common
  x11-xkb-utils xfonts-base xfonts-encodings xfonts-utils xserver-common
  xserver-xorg-core
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
stdin: is not a tty
mount: block device /tmp/VBoxGuestAdditions.iso is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.1.10 - guest version is 5.1.8
stdin: is not a tty
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.10 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Removing installed version 5.1.8 of VirtualBox Guest Additions...
vboxadd-service.sh: Stopping VirtualBox Guest Addition service.
vboxadd.sh: Stopping VirtualBox Additions.
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Building Guest Additions kernel modules.
vboxadd.sh: Starting the VirtualBox Guest Additions.

Could not find the X.Org or XFree86 Window System, skipping.
stdin: is not a tty
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.1.8
VBoxService inside the vm claims: 5.1.10
Going on, assuming VBoxService is correct...
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.1.8
VBoxService inside the vm claims: 5.1.10
Going on, assuming VBoxService is correct...
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/Student/demo

workflow:

1. use box add to give vagrant an image (xxx.box) and give it a tag name, e.g. ubuntu/trusty64
2. vagrant init ubuntu/trusty64 (will create the file Vagrantfile)
3. vagrant up  (set-up the guest node according to the Vagrantfile and then turn on the guest node)
4. vagrant ssh (login to the guest node)

I was trying to find the folder which contains motd(message of the day) settings. This is done by using the forgotten "find" command:

vagrant@vagrant-ubuntu-trusty-64:~$ sudo find / -type d -name "*motd*"
/etc/update-motd.d

check the file system and the harddisk:

root@vagrant-ubuntu-trusty-64:/vagrant# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
4 heads, 32 sectors/track, 655360 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00021928

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    83886079    41942016   83  Linux
root@vagrant-ubuntu-trusty-64:/vagrant# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            241M   12K  241M   1% /dev
tmpfs            49M  344K   49M   1% /run
/dev/sda1        40G  1.4G   37G   4% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            245M     0  245M   0% /run/shm
none            100M     0  100M   0% /run/user
vagrant         201G  124G   77G  62% /vagrant

Indeed, the mounted mount point /vagrant is the directory that is shared in between the host and the guest.

Remark: use hostnamectl to modify the host name when necessary. I am not going to do this.


In [ ]:
%%bash
cd ~/hadoop_base
vagrant up


In [4]:
%%bash
cd ~/hadoop_base
vagrant package --output hadoop_base.box


==> base: Clearing any previously set forwarded ports...
==> base: Exporting VM...
==> base: Compressing package to: C:/Users/Student/hadoop_base/hadoop_base.box

In [5]:
%%bash
cd ~/hadoop_base
vagrant box add iiiedu/hadoop_base hadoop_base.box


==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'iiiedu/hadoop_base' (v0) for provider: 
    box: Unpacking necessary files from: file://C:/Users/Student/hadoop_base/hadoop_base.box
    box: 
==> box: Successfully added box 'iiiedu/hadoop_base' (v0) for 'virtualbox'!

In [8]:
%%bash
vagrant box list


iiiedu/hadoop_base (virtualbox, 0)
iiiedu/trusty64    (virtualbox, 0)
iiiedu/xenial64    (virtualbox, 0)

In [9]:
%%bash
cd ~/
mkdir hadoop_node
cd hadoop_node
vagrant init iiiedu/hadoop_base


A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

In [10]:
%%bash
cd ~/hadoop_node
vagrant up


Bringing machine 'node' up with 'virtualbox' provider...
==> node: Importing base box 'iiiedu/hadoop_base'...
==> node: Matching MAC address for NAT networking...
==> node: Setting the name of the VM: node
==> node: Fixed port collision for 22 => 2222. Now on port 2200.
==> node: Clearing any previously set network interfaces...
==> node: Preparing network interfaces based on configuration...
    node: Adapter 1: nat
==> node: Forwarding ports...
    node: 22 (guest) => 2200 (host) (adapter 1)
==> node: Running 'pre-boot' VM customizations...
==> node: Booting VM...
==> node: Waiting for machine to boot. This may take a few minutes...
    node: SSH address: 127.0.0.1:2200
    node: SSH username: vagrant
    node: SSH auth method: private key
==> node: Machine booted and ready!
[node] GuestAdditions 5.1.10 running --- OK.
==> node: Checking for guest additions in VM...
==> node: Setting hostname...
==> node: Mounting shared folders...
    node: /vagrant => C:/Users/Student/hadoop_node

In [ ]:
%%bash
cd ~/hadoop_cluster
vagrant package master --output master.box
vagrant package slave1 --output slave1.box
vagrant package slave2 --output slave2.box
vagrant package slave3 --output slave3.box
vagrant package slave4 --output slave4.box
vagrant package slave5 --output slave5.box

In [ ]: