This example illustrates how the Docker plugin can be used to create a tagged Docker image from an existing image.
This example named docker-003-image-from-dockerfile-centos, including all configuration files, is included in the default configuration which is created by Pineapple, so there is no need to create it by hand.
Pineapple's unit of work is modules. A module is a self contained unit which can contain models, scripts and binaries. Models serves to specify test cases, deployment of applications, configuration of devices or execution of scripts.
The default directory for modules is ${user.home}/.pineapple/modules so we will create a module named docker-003-image-from-dockerfile-centos there. The module for this example will end up with the structure:
docker-003-image-from-dockerfile-centos | +--- models | +--- linux-vagrant.xml +--- dockersrc +--- Dockerfile
The model file for definition of the image:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <mmd:models xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" xmlns:dkp="http://pineapple.dev.java.net/ns/plugin/docker_1_0" > <mmd:model target-resource="docker-node" description="Define tagged Docker image: pineapple/centos from Dockerfile" > <mmd:content> <dkp:docker> <dkp:image-from-dockerfile source-directory="modulepath:dockersrc" pull-image="false" > <dkp:target-image repository="pineapple/centos" tag="latest" /> </dkp:image-from-dockerfile> </dkp:docker> </mmd:content> </mmd:model> </mmd:models>
Two schema are used in the model file. The http://pineapple.dev.java.net/ns/module_model_1_0 is used to define the namespace mmd which defines the general infrastructure for models. The http://pineapple.dev.java.net/ns/plugin/docker_1_0 schema is used to define the namespace dkp which is used to define the model for the Docker plugin. Since multiple schemas are used to define the model file, the elements are qualified.
The model file contains two model elements each of which defines a model. Both models defines usage of the Docker plugin:
The dkp:image-from-dockerfile element defines a tagged Docker image which can be used for creation or deletion depending on the invoked operation:
When the model is invoked with the deploy-configuration operation, then target image is created from the source image. The source image is defined by the DockerFile (detail below).
When the image is created then source directory, defined by the source-directory attribute on element dkp:image-from-dockerfile, is compressed into a TAR archive and uploaded to Docker. Please notice that source directory is defined using the variable modulepath:dockersrc which is resolved at runtime to the directory dockersrc within the module.
Docker unpacks the archive and looks for a Dockerfile in the root of the archive. The Dockerfile along with other file material in the archive is used to create the image.
The name of the target image is defined by the dkp:target-image element.
The Dockerfile contains:
# Pull base image # --------------- FROM centos:latest # Maintainer # ---------- MAINTAINER Allan Thrane Andersen <einheriii@gmail.com>
The FROM command specifies that the image centos:latest should be pulled from DockerHub.
The MAINTAINER command declares the proud author.