<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog4Java &#187; Docker</title>
	<atom:link href="http://malsolo.com/blog4java/?feed=rss2&#038;tag=docker" rel="self" type="application/rss+xml" />
	<link>http://malsolo.com/blog4java</link>
	<description>A personal and Java blog, likely only for me</description>
	<lastBuildDate>Tue, 31 Mar 2015 15:52:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Getting started with Docker</title>
		<link>http://malsolo.com/blog4java/?p=794</link>
		<comments>http://malsolo.com/blog4java/?p=794#comments</comments>
		<pubDate>Tue, 31 Mar 2015 15:51:23 +0000</pubDate>
		<dc:creator><![CDATA[Javier (@jbbarquero)]]></dc:creator>
		
		<guid isPermaLink="false">http://malsolo.com/blog4java/?p=794</guid>
		<description><![CDATA[What is Docker? Docker is a platform. Docker runs natively on Linux or on OS X and Windows through a helper application called boot2docker that creates a Linux Virtual Machine, by using only RAM, to run Docker. Docker&#8216;s main goal &#8230; <a href="http://malsolo.com/blog4java/?p=794">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h1>What is Docker?</h1>
<p><a href="https://www.docker.com/whatisdocker/" title="What is Docker?" target="_blank">Docker</a> is a platform.</p>
<p><a href="https://docs.docker.com/introduction/understanding-docker/" title="Understanding Docker" target="_blank">Docker</a> runs natively on Linux or on OS X and Windows through a helper application called <a href="https://github.com/boot2docker/boot2docker" title="boot2docker at GitHub" target="_blank">boot2docker</a> that creates a Linux Virtual Machine, by using only RAM, to run Docker.</p>
<p><a href="https://docs.docker.com/" title="About Docker" target="_blank">Docker</a>&#8216;s main goal is to allow you to ship distributed applications, that you&#8217;ve created previously, by running them as isolated process on what is known as a <em>container</em>, thus it avoids the need of Virtual Machines that implies a resources saving in the involved machines. The isolation also allows to run several containers simultaneously.</p>
<p>So, <em><strong>Docker</strong> is an open platform for developing, shipping, and running applications</em>.</p>
<p>The key point is that you can separate your application from the infrastructure and also treats the infrastructure as an application. Everything can be packaged, distributed and deployed anywhere and quickly. It&#8217;s said that Docker eliminates the friction between development, QA, and production environments.</p>
<p>Docker has two major <strong>components</strong>:</p>
<ul>
<li><a href="https://github.com/docker/docker" title="Docker at GitHub" target="_blank">Docker</a>, the container virtualization platform, that has a <em>daemon</em> running on a host server and a client (the <em>docker</em> binary) to talk to the Docker <em>daemon</em>.</li>
<li><a href="https://hub.docker.com/" title="Docker Hub" target="_blank">Docker Hub</a>, the <a href="http://en.wikipedia.org/wiki/Software_as_a_service" title="Software as a service at Wikipedia" target="_blank">SaaS</a> platform for sharing and managing Docker containers.</li>
</ul>
<h2>Docker concepts</h2>
<ul>
<li><strong>Image</strong> (<em>build</em> component of Docker): a Docker environment template, it consists in files (a copy of what is expected to contain) and metadata (information such as environment variables, port mappings and so on) and it has a name (<em>&#8220;ubuntu&#8221;</em>, for instance)</li>
<li><strong>Registry</strong> (<em>distribution</em> component of Docker): a public or private store that holds images. The public Docker registry is called <a href="http://hub.docker.com/" title="Docker Hub" target="_blank">Docker Hub</a>.</li>
<li><strong>Container</strong> (<em>run</em> component of Docker):  a running instance of a Docker image. It&#8217;s created from a Docker image, and it can be run, started, stopped, moved, and deleted. Each container is an isolated and secure application platform.</li>
</ul>
<h2>How Does Docker work?</h2>
<p>An image is a serie of layers that are combined into a single image by Docker using <em><strong>union file systems</strong></em> (<a href="http://en.wikipedia.org/wiki/UnionFS" title="UnionFS at Wikipedia" target="_blank">UnionFS</a>, <em>a file system service that allows files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system</em>)</p>
<p>From a base image, you can add and modify additional layers and there&#8217;s no need of rebuilding the entire image if there is a change, you only need replace the added or updated layer.  </p>
<p>A container is built from an image, that is read-only. For running the container, Docker adds a read-write layer on top of the image (using UnionFS) and then allocates a network/bridge interface, an IP address, and finally, executes the specified process and captures input and provides output.</p>
<p>The container is isolated thanks to a technology called <em><strong>namespaces</strong></em> (<a href="http://en.wikipedia.org/wiki/Cgroups#NAMESPACE-ISOLATION" title="Namespaces at Wikipedia" target="_blank">Namespace isolation</a>, <em>where groups of processes are separated such that they cannot &#8220;see&#8221; resources in other groups</em>)</p>
<p>Docker use these namespaces:</p>
<ul>
<li>The <strong>pid</strong> namespace, for process isolation.</li>
<li>The <strong>net</strong> namespace, for managing network interfaces.</li>
<li>The <strong>ipc</strong> namespace, for Inter-Process Communication.</li>
<li>The <strong>mnt</strong> namespace, for managing mount-points.</li>
<li>The <strong>uts</strong> namespace, for changing the hostname.</li>
</ul>
<p>In order to achieve isolation on running application, Docker uses another technology called <em><strong>control groups</strong></em> (<a href="http://en.wikipedia.org/wiki/Cgroups" title="cgroups at Wikipedia" target="_blank">cgroups</a>, <em>it limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes</em>)</p>
<h1>Installing Docker</h1>
<p>I&#8217;m going to use <a href="http://www.ubuntu.com/" title="Ubuntu: The leading OS for PC, tablet, phone and cloud" target="_blank">Ubuntu</a> (as <a href="http://en.wikipedia.org/wiki/Sheldon_Cooper" title="Sheldon Cooper at Wikipedia" target="_blank">Sheldon Cooper</a> said, <a href="http://www.imdb.com/title/tt1648756/quotes?item=qt1224150" title="Sheldon Cooper and Ubuntu" target="_blank">my favorite Linux-based operating system</a>)</p>
<p>There are <u>three packages available</u>, two of them from Ubuntu, an older KDE3/GNOME2 called <em>docker</em> (warning, this is the suggested package when you try <em>docker version</em> before having installed: <em>&#8220;The program &#8216;docker&#8217; is currently not installed. You can install it by typing: sudo apt-get install docker&#8221;</em>) and a newer called <em>docker.io</em>, that is not the most recent Docker release. The third one is a PPA (Personal Package Archives for Ubuntu) for <a href="http://www.ubuntuupdates.org/ppa/docker" title="3rd Party Repository: Docker" target="_blank">Docker</a> and it&#8217;s called <a href="http://www.ubuntuupdates.org/package/docker/docker/main/base/lxc-docker" title="Ubuntu Package &quot;lxc-docker&quot;" target="_blank"><em>lxc-docker</em></a>.</p>
<p>If you don&#8217;t want extra repositories and you don&#8217;t want the latest version, just install <em>docker.io</em> (I recommend you to enable tab-completion of Docker commands in BASH if you install it):</p>
<p></p><pre class="crayon-plain-tag">$ sudo apt-get update
$ sudo apt-get install docker.io
$ source /etc/bash_completion.d/docker.io</pre><p></p>
<p>To validate the installation, type:</p><pre class="crayon-plain-tag">$ sudo docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.2.1
Git commit (client): 990021a
Server version: 1.0.1
Server API version: 1.12
Go version (server): go1.2.1
Git commit (server): 990021a
$</pre><p></p>
<p>You need to use <strong>sudo</strong> because the <em>docker</em> daemon always runs as the <em>root</em> user, that&#8217;s because the <em>docker</em> daemon binds to a Unix socket (instead of a TCP port, as it happened until version 0.5.2). By default that Unix socket is owned by the user <em>root</em>, so you need to use the <em>docker</em> command with <em>sudo</em>. You can solve it by <a href="http://docs.docker.com/v1.4/installation/ubuntulinux/#giving-non-root-access" title="Giving non-root access" target="_blank">giving non-root access to Docker</a> or, even better, you can <a href="https://docs.docker.com/installation/ubuntulinux/#create-a-docker-group" title="Create a docker group" target="_blank">create a docker group and add users to it</a>.</p>
<p>Otherwise, if you run docker without sudo you will obtain this error message:</p><pre class="crayon-plain-tag">$ docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.2.1
Git commit (client): 990021a
2015/03/20 11:40:30 Get http:///var/run/docker.sock/v1.12/version: dial unix /var/run/docker.sock: permission denied
$</pre><p></p>
<p>In order to have the latest version, use the <em>lxc-docker</em> package, that is the one maintained by Docker itself.</p>
<p>There is a <a href="https://get.docker.com/ubuntu/" title="Get Docker on Ubuntu" target="_blank">script to install the Docker package on Ubuntu</a>, but I&#8217;d rather to do it manually. But you can try with:</p>
<p></p><pre class="crayon-plain-tag">$ curl -sSL https://get.docker.com/ubuntu/ | sudo sh</pre><p></p>
<p>To install lxc-docker, your APT system have to deal with https (you can if the file <em>/usr/lib/apt/methods/https</em> exists, it you don&#8217;t have it, install the <em><strong>apt-transport-https</strong></em> package)</p>
<p>Then, just add the Docker repository key to the local keychain, and to the apt sources list. Finally, update and install the <em><strong>lxc-docker</strong></em> package:</p>
<p></p><pre class="crayon-plain-tag">$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
$ sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker</pre><p></p>
<p>Now we have the last version:</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef
$</pre><p></p>
<p>And we can run the basic example, that downloads the <em>ubuntu</em> image, and then start <em>bash</em> in a container. When you&#8217;re done, type <em>exit</em>.</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
511136ea3c5a: Pull complete 
f3c84ac3a053: Pull complete 
511136ea3c5a: Download complete 
f3c84ac3a053: Download complete 
a1a958a24818: Download complete 
9fec74352904: Download complete 
d0955f21bf24: Download complete 
Status: Downloaded newer image for ubuntu:latest
root@0f5e5a64c583:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
root@0f5e5a64c583:/# exit
exit
$</pre><p></p>
<p>Having said that, Docker has changed the instructions for <a href="https://docs.docker.com/installation/ubuntulinux/#installing-docker-on-ubuntu" title="Installing Docker on Ubuntu" target="_blank">Installing Docker on Ubuntu</a>&#8230; today! <img src="http://malsolo.com/blog4java/wp-includes/images/smilies/icon_neutral.gif" alt=":|" class="wp-smiley" /></p>
<p>It seems easier, but I don’t like it very much. If you have wget installed, you can get the latest Docker package with:</p>
<p></p><pre class="crayon-plain-tag">$ wget -qO- https://get.docker.com/ | sh</pre><p></p>
<p>It prompts for the password and then it downloads and installs&#8230; the <em>lxc-docker</em> package. </p>
<p>And then, verify the installation with:</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker run hello-world
[sudo] password for Javier: 
Unable to find image 'hello-world:latest' locally
31cbccb51277: Pull complete 
e45a5af57b00: Pull complete 
511136ea3c5a: Already exists 
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Status: Downloaded newer image for hello-world:latest
Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (Assuming it was not already locally available.)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

For more examples and ideas, visit:
 http://docs.docker.com/userguide/
$</pre><p></p>
<h1>Using Docker</h1>
<h2>Running applications inside containers</h2>
<p>Docker allows you to run applications inside containers with the command <strong><em>docker run</em></strong>.</p>
<p>The command <em>docker run</em> creates a new container from the image name that you specify (the mandatory parameter for <em>run</em>) and then runs the command in it by performing these steps: Docker looks for the image in this computer, if it isn&#8217;t installed yet, Docker searches the image at Docker Hub to download it and install it. Once the image is installed, Docker creates a new container and starts the program.</p>
<p>We&#8217;ve seen above one example:</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker run -t -i ubuntu:14.04.2 /bin/bash</pre><p></p>
<p>It creates a container from the <a href="https://registry.hub.docker.com/_/ubuntu/" title="Docker Hub: Official Ubuntu base image" target="_blank">Official Ubuntu base image</a> (tag 14.04.2) and then it runs a Bash shell command, with a terminal assigned (flag <strong>-t</strong>), and grabs the standard in of the container(flag <strong>-i</strong>)</p>
<p>For executing in the background (or daemonized), use the <strong>-d</strong> flag:</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker run -d --name="Javier" ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
e84ae64138881b9eaf6ac743c6f0076cfc414f017daef9e59c3d2e1d591eb7b9</pre><p></p>
<p>Here, the command will run forever. Besides, I have assigned a name to the container (OK, my very name, some egocentricity here) to easily discover it later (Docker automatically names any containers that you start, but I&#8217;d rather to specify the name by myself). Furthermore, Docker returns the container ID (<em>e84ae6413888&#8230;</em>).</p>
<p>You can find both the ID and the name when listing containers with the command <em><strong>docker ps</strong></em> (flag <strong>-a</strong> to show all regardless they are running or not)</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
e84ae6413888        ubuntu:14.04        "/bin/sh -c 'while t   5 days ago          Up 2 minutes                            Javier              
$</pre><p></p>
<p>The <strong>ports</strong> in the container can be exposed randomly with the <strong>-P</strong> flag or manually with <strong>-p</strong>. In any case, you can see in the column <em>PORTS</em> of the <em>docker ps</em> command or with the <em>docker port</em> command. Let&#8217;s see an example with a <a href="https://registry.hub.docker.com/u/training/webapp/" title="The Docker Fundamentals repository contains the example Hello World Python WebApp" target="_blank">sample web application image</a>.</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker run -d -P training/webapp python app.py
Unable to find image 'training/webapp:latest' locally
Pulling repository training/webapp
31fa814ba25a: Download complete 
511136ea3c5a: Download complete 
f10ebce2c0e1: Download complete 
82cdea7ab5b5: Download complete 
5dbd9cb5a02f: Download complete 
74fe38d11401: Download complete 
64523f641a05: Download complete 
0e2afc9aad6e: Download complete 
e8fc7643ceb1: Download complete 
733b0e3dbcee: Download complete 
a1feb043c441: Download complete 
e12923494f6a: Download complete 
a15f98c46748: Download complete 
Status: Downloaded newer image for training/webapp:latest
a03ec94ea8087789d605ca91d6689d8026e7806e9138b8b9b7ed7f5a1295db85
$ sudo docker ps
CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS                     NAMES
a03ec94ea808        training/webapp:latest   "python app.py"     25 seconds ago      Up 24 seconds       0.0.0.0:49153->5000/tcp   happy_pare          
$ sudo docker port happy_pare
5000/tcp -> 0.0.0.0:49153
$ curl http://localhost:49153
Hello world!
$</pre><p></p>
<p>This means that you can access the application running in the container by using the port 49153 locally.</p>
<p>To manage the container, you can use the next commands:</p>
<ul>
<li><em><strong>docker logs</strong></em> to see the standard output of a container (<strong>-f</strong> to view the new additions, press Ctrl+C to exit)</li>
<li><em><strong>docker top</strong></em> to see the process in the container.</li>
<li><em><strong>docker inspect</strong></em> to see configuration and status information about a container.</li>
<li><em><strong>docker stop/kill</strong></em> to stop or kills (respectively) a running container.</li>
<li><em><strong>docker start</strong></em> to restart a stopped container (remember the command <em>docker ps -a</em>).</li>
<li><em><strong>docker rm</strong></em> to remove a container.</li>
<li><em><strong>docker version</strong></em> to see the current version of the program, its programming language (<a href="https://golang.org/" title="The Go Programming Language" target="_blank">Go</a>) and so on.</li>
</ul>
<p></p><pre class="crayon-plain-tag">$ sudo docker logs happy_pare
 * Running on http://0.0.0.0:5000/
172.17.42.1 - - [31/Mar/2015 09:51:38] "GET / HTTP/1.1" 200 -
$ sudo docker stop happy_pare
happy_pare
$ sudo docker start happy_pare
happy_pare
$ sudo docker kill happy_pare
happy_pare
$ sudo docker rm happy_pare
happy_pare
$ sudo docker top happy_pare
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                8580                1372                0                   12:00               ?                   00:00:00            python app.py
$ sudo docker inspect hungry_kirch
[{
    "AppArmorProfile": "",
    "Args": [
        "app.py"
    ],
    "Config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "python",
            "app.py"
        ],
        "CpuShares": 0,
        "Cpuset": "",
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "HOME=/",
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "ExposedPorts": {
            "5000/tcp": {}
        },
        "Hostname": "468cd593eada",
        "Image": "training/webapp",
        "MacAddress": "",
        "Memory": 0,
        "MemorySwap": 0,
        "NetworkDisabled": false,
        "OnBuild": null,
        "OpenStdin": false,
        "PortSpecs": null,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "Volumes": null,
        "WorkingDir": "/opt/webapp"
    },
    "Created": "2015-03-31T10:00:32.697111567Z",
    "Driver": "aufs",
    "ExecDriver": "native-0.2",
    "ExecIDs": null,
    "HostConfig": {
        "Binds": null,
        "CapAdd": null,
        "CapDrop": null,
        "ContainerIDFile": "",
        "Devices": [],
        "Dns": null,
        "DnsSearch": null,
        "ExtraHosts": null,
        "IpcMode": "",
        "Links": null,
        "LxcConf": [],
        "NetworkMode": "bridge",
        "PidMode": "",
        "PortBindings": {},
        "Privileged": false,
        "PublishAllPorts": true,
        "ReadonlyRootfs": false,
        "RestartPolicy": {
            "MaximumRetryCount": 0,
            "Name": ""
        },
        "SecurityOpt": null,
        "VolumesFrom": null
    },
    "HostnamePath": "/var/lib/docker/containers/468cd593eadaea6d18441a33ca6c1ea42f1b398d6fd028fa5b557181a5cf36f3/hostname",
    "HostsPath": "/var/lib/docker/containers/468cd593eadaea6d18441a33ca6c1ea42f1b398d6fd028fa5b557181a5cf36f3/hosts",
    "Id": "468cd593eadaea6d18441a33ca6c1ea42f1b398d6fd028fa5b557181a5cf36f3",
    "Image": "31fa814ba25ae3426f8710df7a48d567d4022527ef2c14964bb8bc45e653417c",
    "MountLabel": "",
    "Name": "/hungry_kirch",
    "NetworkSettings": {
        "Bridge": "docker0",
        "Gateway": "172.17.42.1",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "IPAddress": "172.17.0.10",
        "IPPrefixLen": 16,
        "IPv6Gateway": "",
        "LinkLocalIPv6Address": "fe80::42:acff:fe11:a",
        "LinkLocalIPv6PrefixLen": 64,
        "MacAddress": "02:42:ac:11:00:0a",
        "PortMapping": null,
        "Ports": {
            "5000/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "49155"
                }
            ]
        }
    },
    "Path": "python",
    "ProcessLabel": "",
    "ResolvConfPath": "/var/lib/docker/containers/468cd593eadaea6d18441a33ca6c1ea42f1b398d6fd028fa5b557181a5cf36f3/resolv.conf",
    "RestartCount": 0,
    "State": {
        "Error": "",
        "ExitCode": 0,
        "FinishedAt": "0001-01-01T00:00:00Z",
        "OOMKilled": false,
        "Paused": false,
        "Pid": 8580,
        "Restarting": false,
        "Running": true,
        "StartedAt": "2015-03-31T10:00:32.898205331Z"
    },
    "Volumes": {},
    "VolumesRW": {}
}
]
$</pre><p></p>
<h2>Working with Docker Images</h2>
<p>As we have explained, Docker runs container by using images that are either installed in your system or exists at <a href="https://hub.docker.com/" title="Docker Hub" target="_blank">Docker Hub</a> (in order to download it and install in your system)</p>
<p>You can see what images are already installed with the <strong><em>docker images</em></strong> command.  </p>
<p></p><pre class="crayon-plain-tag">$ sudo docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu                  trusty-20150320     d0955f21bf24        11 days ago         188.3 MB
ubuntu                  14.04               d0955f21bf24        11 days ago         188.3 MB
ubuntu                  14.04.2             d0955f21bf24        11 days ago         188.3 MB
ubuntu                  latest              d0955f21bf24        11 days ago         188.3 MB
ubuntu                  trusty              d0955f21bf24        11 days ago         188.3 MB
training/webapp         latest              31fa814ba25a        10 months ago       278.8 MB
$</pre><p></p>
<p>If you want to manually install an image before running it, you can use the <strong><em>docker pull</em></strong> command for images that you can find at <a href="https://hub.docker.com/" title="Docker Hub" target="_blank">Docker Hub</a> or with the command <strong><em>docker search</em></strong>. </p>
<p>As a curiosity, if you look for images at Docker Hub, you can find Official repos, for instance, the <a href="Java OFFICIAL REPO" title="https://registry.hub.docker.com/_/java/" target="_blank">Java OFFICIAL REPO</a>.</p>
<p>You can add a new name to the image with the <strong><em>docker tag</em></strong>.</p>
<p>If you want to remove an image, you can do so with the <strong><em>docker rmi</em></strong> command.</p>
<h3>A note about the official images</h3>
<p>The images and relevant files are maintained at GitHub by an organization called <a href="https://github.com/docker-library" title="docker-library" target="_blank">docker-library</a> (Docker is open source, and it&#8217;s maintained at GitHub by an organization called <a href="https://github.com/docker" title="Docker" target="_blank">Docker</a>, that has several repositories, including the one for <a href="https://github.com/docker/docker" title="Docker - the open-source application container engine" target="_blank">docker</a>).</p>
<p>The official images exist in a repository, <a href="https://github.com/docker-library/official-images" title="Docker Official Images" target="_blank">Docker Official Images</a>, that contains a folder for the <a href="https://github.com/docker-library/official-images/tree/master/library" title="official-images/library" target="_blank">library definitions</a>, for instance, the one for <a href="https://github.com/docker-library/official-images/blob/master/library/java" title="official-images/library/java" target="_blank">java</a>.</p>
<p>The image packages are also maintained by docker-library in each corresponding repository, for instance, the <a href="https://github.com/docker-library/java" title="Docker Official Image packaging for Java (openJDK)" target="_blank">Docker Official Image packaging for Java</a> (<a href="http://openjdk.java.net/" title="OpenJDK" target="_blank">openJDK</a>)</p>
<p>It&#8217;s worth to mention it because there is another organization at GitHub called <a href="https://github.com/dockerfile" title="Dockerfile Project" target="_blank"></a> (<em>Trusted Automated Docker Builds</em>) that has repositories for several Docker builds, for instance, the one for <a href="https://github.com/dockerfile/java" title="Java Dockerfile for trusted automated Docker builds" target="_blank">Java</a>, that includes an image for <a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html" title="Java SE Development Kit 8 Downloads" target="_blank">Oracle Java 8 JDK</a> (that I was looking for) </p>
<h3>Creating your own images</h3>
<p>There are two ways for updating and creating images.</p>
<ol>
<li>Run a container from an image (<em>docker run</em>), then update it, and finally commit the results to an image, with the <em><strong>docker commit</strong></em> command.</li>
<li>Use a <em><strong>Dockerfile</strong></em> to create an image.</li>
</ol>
<p>When you&#8217;re done, you can push the created image to Docker Hub with the <strong><em>docker push</em></strong> command.</p>
<p>Finally, you can remove images with the <strong><em>docker rmi</em></strong> command.</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker run -t -i ubuntu:latest /bin/bash
root@98bec5327540:/# sudo apt-get install --reinstall software-properties-common
root@98bec5327540:/# sudo add-apt-repository ppa:webupd8team/java
root@98bec5327540:/# sudo apt-get update
root@98bec5327540:/# sudo apt-get install oracle-java8-installer
root@98bec5327540:/# sudo apt-get install nano
root@98bec5327540:/# wget http://apache.rediris.es/maven/maven-3/3.3.1/binaries/apache-maven-3.3.1-bin.tar.gz
root@98bec5327540:/# tar -xvf apache-maven-3.3.1-bin.tar.gz 
root@98bec5327540:/# cp -r apache-maven-3.3.1 /usr/local/apache-maven
root@98bec5327540:/# sudo nano /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/apache-maven/bin"
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
MAVEN_OPTS="-Xms256m -Xmx512m"
root@98bec5327540:/# source /etc/environment 
root@98bec5327540:/# echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
root@98bec5327540:/# java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
root@98bec5327540:/# mvn -version
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T20:10:27+00:00)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_40, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.13.0-48-generic", arch: "amd64", family: "unix"
root@98bec5327540:/# exit
$ sudo docker ps -a
CONTAINER ID        IMAGE                    COMMAND                CREATED             STATUS                        PORTS               NAMES
98bec5327540        ubuntu:14.04             "/bin/bash"            47 minutes ago      Exited (0) 4 minutes ago                          determined_carson   
468cd593eada        training/webapp:latest   "python app.py"        2 hours ago         Exited (137) 2 minutes ago                        hungry_kirch        
e84ae6413888        ubuntu:14.04             "/bin/sh -c 'while t   5 days ago          Exited (137) 3 hours ago                          Javier              
0f5e5a64c583        ubuntu:14.04             "/bin/bash"            11 days ago         Exited (0) 11 days ago                            dreamy_hopper     

$ sudo docker commit -m "Ubuntu latest (14.04) with  Oracle Java 8 JDK and Apache Maven 3.3.1 (and nano editor)" -a "Javier Beneito Barquero" 98bec5327540 jbbarquero/ubuntu-java8_oracle-maven
e262639379c46afa53eca74de9df9bd2f81e0ab7839a3472cafb67d7e199d85e
$

$ sudo docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jbbarquero/ubuntu-java8_oracle-maven   latest              e262639379c4        56 seconds ago      828 MB
ubuntu                                 14.04               d0955f21bf24        11 days ago         188.3 MB
ubuntu                                 14.04.2             d0955f21bf24        11 days ago         188.3 MB
ubuntu                                 latest              d0955f21bf24        11 days ago         188.3 MB
ubuntu                                 trusty              d0955f21bf24        11 days ago         188.3 MB
ubuntu                                 trusty-20150320     d0955f21bf24        11 days ago         188.3 MB
centos                                 latest              88f9454e60dd        3 weeks ago         210 MB
hello-world                            latest              e45a5af57b00        12 weeks ago        910 B
training/webapp                        latest              31fa814ba25a        10 months ago       278.8 MB
$ sudo docker tag jbbarquero/ubuntu-java8_oracle-maven my-java8
$ sudo docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED              VIRTUAL SIZE
jbbarquero/ubuntu-java8_oracle-maven   latest              e262639379c4        About a minute ago   828 MB
my-java8                               latest              e262639379c4        About a minute ago   828 MB
ubuntu                                 trusty-20150320     d0955f21bf24        11 days ago          188.3 MB
ubuntu                                 14.04               d0955f21bf24        11 days ago          188.3 MB
ubuntu                                 14.04.2             d0955f21bf24        11 days ago          188.3 MB
ubuntu                                 latest              d0955f21bf24        11 days ago          188.3 MB
ubuntu                                 trusty              d0955f21bf24        11 days ago          188.3 MB
centos                                 latest              88f9454e60dd        3 weeks ago          210 MB
hello-world                            latest              e45a5af57b00        12 weeks ago         910 B
training/webapp                        latest              31fa814ba25a        10 months ago        278.8 MB

$ sudo docker run -t -i my-java8 /bin/bash
root@da1045b88138:/# mvn -version
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T20:10:27+00:00)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_40, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.13.0-48-generic", arch: "amd64", family: "unix"
root@da1045b88138:/# exit
exit
$ 

$ sudo docker push jbbarquero/ubuntu-java8_oracle-maven
The push refers to a repository [jbbarquero/ubuntu-java8_oracle-maven] (len: 1)
Sending image list

Please login prior to push:
Username: jbbarquero
Password: 
Email: jbbarquero@gmail.com
Login Succeeded
The push refers to a repository [jbbarquero/ubuntu-java8_oracle-maven] (len: 1)
Sending image list
Pushing repository jbbarquero/ubuntu-java8_oracle-maven (1 tags)
511136ea3c5a: Image already pushed, skipping 
f3c84ac3a053: Image already pushed, skipping 
a1a958a24818: Image already pushed, skipping 
9fec74352904: Image already pushed, skipping 
d0955f21bf24: Image already pushed, skipping 
e262639379c4: Image successfully pushed 
Pushing tag for rev [e262639379c4] on {https://cdn-registry-1.docker.io/v1/repositories/jbbarquero/ubuntu-java8_oracle-maven/tags/latest}
$</pre><p></p>
<p>You can find this image at <a href="https://registry.hub.docker.com/u/jbbarquero/ubuntu-java8_oracle-maven/" title="jbbarquero / ubuntu-java8_oracle-maven" target="_blank">jbbarquero / ubuntu-java8_oracle-maven</a></p>
<p>How to <a href="https://docs.docker.com/reference/builder/" title="Dockerfile Reference" target="_blank">write a Dockerfile</a> is out of the bounds of this first post, but I can create a very basic one. Just for fun.</p>
<p>Having this Dockerfile:</p>
<p></p><pre class="crayon-plain-tag"># This is a comment
FROM jbbarquero/ubuntu-java8_oracle-maven
MAINTAINER Javier Beneito Barquero &lt;jbbarquero@gmail.com&gt;
RUN apt-get update &amp;&amp; apt-get install -y git</pre><p></p>
<p>Just build it (and then push it)</p>
<p></p><pre class="crayon-plain-tag">$ sudo docker build -t jbbarquero/ubuntu-java8_oracle-maven-git .
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon 
Step 0 : FROM jbbarquero/ubuntu-java8_oracle-maven
 ---> e262639379c4
Step 1 : MAINTAINER Javier Beneito Barquero <jbbarquero@gmail.com>
 ---> Running in d1be5fc2ed6e
 ---> 162fdb8b3a3d
Removing intermediate container d1be5fc2ed6e
Step 2 : RUN apt-get update && apt-get install -y git
 ---> Running in b7c2cf318638

... Lot of installation messages here

 ---> f63b88cf14ab
Removing intermediate container b7c2cf318638
Successfully built f63b88cf14ab
$ sudo docker images
REPOSITORY                                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jbbarquero/ubuntu-java8_oracle-maven-git   latest              f63b88cf14ab        17 seconds ago      876.5 MB
...

$ sudo docker run -t -i jbbarquero/ubuntu-java8_oracle-maven-git /bin/bash
root@bb9caa298372:/# git --version
git version 1.9.1
root@bb9caa298372:/# mvn -version
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T20:10:27+00:00)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_40, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.13.0-48-generic", arch: "amd64", family: "unix"
root@bb9caa298372:/# exit
exit</pre><p></p>
<p>The new image can be found in Docker Hub, find it at <a href="https://registry.hub.docker.com/u/jbbarquero/ubuntu-java8_oracle-maven-git/http://" title="jbbarquero / ubuntu-java8_oracle-maven-git" target="_blank">jbbarquero / ubuntu-java8_oracle-maven-git</a>.</p>
<h1>Closing words</h1>
<p>That&#8217;s enough for now. There are a couple of interesting topics, but we&#8217;ll leave for another time:</p>
<ul>
<li><a href="https://docs.docker.com/userguide/dockerlinks/" title="Linking Containers Together" target="_blank">Linking Containers</a>, for sending information between containers in Docker.</li>
<li><a href="https://docs.docker.com/userguide/dockervolumes/" title="Managing Data in Containers" target="_blank">Data in containers</a>, for managing data volumes.</li>
</ul>
<h1>Resources</h1>
<ul>
<li><a href="https://docs.docker.com/" title="Docker docs" target="_blank">Docker official documentation</a></li>
<li><a href="https://www.docker.com/tryit/" title="Docker, try it!" target="_blank">Docker 10-minute tutorial</a></li>
<li><a href="https://docs.docker.com/installation/ubuntulinux/" title="Docker installation: Ubuntu" target="_blank">Docker installation: Ubuntu</a></li>
<li><a href="http://www.manning.com/nickoloff/" title="Docker in Action" target="_blank">Docker in Action</a>. By Jeff Nickoloff (Manning)</li>
<li><a href="http://www.manning.com/miell/" title="Docker in Practice" target="_blank">Docker in Practice</a>. By Ian Miell and Aidan Hobson Sayers (Manning)</li>
</li>
<li><a href="http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html" title="install oracle java 8 in ubuntu via ppa repository [jdk8]" target="_blank">Install oracle java 8 in ubuntu via ppa repository [jdk8]</a></li>
<li><a href="http://askubuntu.com/questions/38021/how-to-add-a-ppa-on-a-server" title="How to add a PPA on a server?" target="_blank">How to add a PPA on a server?</a></li>
<li><a href="https://help.ubuntu.com/community/Nano" title="Nano" target="_blank">Nano at Ubuntu</a></li>
<li><a href="https://maven.apache.org/download.cgi" title="Download Apache Maven 3.3.1" target="_blank">Download Apache Maven 3.3.1</a></li>
</ul>
<h1>Post scríptum</h1>
<p>When re-starting the container jbbarquero/ubuntu-java8_oracle-maven, <em>source /etc/environment</em> is not called, so the values that I wrote there are not applied. For solving this issue, I edited /etc/bash.bashrc and I put there the environment variables.</p>
<p></p><pre class="crayon-plain-tag">root@98bec5327540:/# sudo nano /etc/bash.bashrc
$ sudo docker start -i 98bec5327540
root@98bec5327540:/# sudo nano /etc/bash.bashrc

JAVA_HOME="/usr/lib/jvm/java-8-oracle"
export JAVA_HOME

M2_HOME=/usr/local/apache-maven
export M2_HOME
M2=$M2_HOME/bin
export M2

PATH=$PATH:$JAVA_HOME
PATH=$PATH:$M2
export PATH

root@98bec5327540:/# exit</pre><p></p>
<p>Maybe a <strong>Dockerfile</strong> is a better idea to create containers with <a href="https://docs.docker.com/reference/builder/#env" title="Dockerfile Reference: ENV instruction" target="_blank">environment variables using ENV</a>.<br />
so the values that I wrote there</p>
]]></content:encoded>
			<wfw:commentRss>http://malsolo.com/blog4java/?feed=rss2&#038;p=794</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
