Commit e8768785 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

website: add docs for docker-import and docker-push

parent c18b74e9
......@@ -20,6 +20,9 @@ type Driver interface {
// Pull should pull down the given image.
Pull(image string) error
// Push pushes an image to a Docker index/registry.
Push(name string) error
// StartContainer starts a container and returns the ID for that container,
// along with a potential error.
StartContainer(*ContainerConfig) (string, error)
......
......@@ -93,6 +93,11 @@ func (d *DockerDriver) Pull(image string) error {
return runAndStream(cmd, d.Ui)
}
func (d *DockerDriver) Push(name string) error {
cmd := exec.Command("docker", "push", name)
return runAndStream(cmd, d.Ui)
}
func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) {
// Build up the template data
var tplData startContainerTemplate
......
......@@ -16,6 +16,10 @@ type MockDriver struct {
ImportId string
ImportErr error
PushCalled bool
PushName string
PushErr error
ExportReader io.Reader
ExportError error
PullError error
......@@ -68,6 +72,12 @@ func (d *MockDriver) Pull(image string) error {
return d.PullError
}
func (d *MockDriver) Push(name string) error {
d.PushCalled = true
d.PushName = name
return d.PushErr
}
func (d *MockDriver) StartContainer(config *ContainerConfig) (string, error) {
d.StartCalled = true
d.StartConfig = config
......
......@@ -64,15 +64,31 @@ Optional:
`["run", "-d", "-i", "-t", "-v", "{{.Volumes}}", "{{.Image}}", "/bin/bash"]`.
As you can see, you have a couple template variables to customize, as well.
## Using the generated artifact
## Using the Artifact
Once the tar artifact has been generated, you will likely want to import, tag,
and push it to a container repository. Until packer supports management of the
docker image metadata, this process is manual. For example, the following will
import `mycontainer-123456789.tar` to the repository
`registry.mydomain.com/mycontainer`, tagged with `latest`:
and push it to a container repository. Packer can do this for you automatically
with the [docker-import](/docs/post-processors/docker-import.html) and
[docker-push](/docs/post-processors/docker-push.html) post-processors.
sudo docker import - registry.mydomain.com/mycontainer:latest < mycontainer-123456789.tar
The example below shows a full configuration that would import and push
the created image:
<pre class="prettyprint">
{
"post-processors": [
[
{ "type": "docker-import", "repository": "mitchellh/packer", "tag": "0.7" },
"docker-push"
]
]
}
</pre>
If you want to do this manually, however, perhaps from a script, you can
import the image using the process below:
docker import - registry.mydomain.com/mycontainer:latest < artifact.tar
You can then add additional tags and push the image as usual with `docker tag`
and `docker push`, respectively.
......@@ -103,8 +119,3 @@ by Packer in the future:
volumes, and other metadata. Packer builds a raw Docker container image
that has none of this metadata. You can pass in much of this metadata
at runtime with `docker run`.
* Images made without dockerfiles are missing critical metadata that
make them easily pushable to the Docker registry. You can work around
this by using a metadata-only Dockerfile with the exported image and
building that. A future Packer version will automatically do this for you.
---
layout: "docs"
page_title: "docker-import Post-Processor"
---
# Docker Import Post-Processor
Type: `docker-import`
The Docker import post-processor takes an artifact from the
[docker builder](/docs/builders/docker.html) and imports it with Docker
locally. This allows you to apply a repository and tag to the image
and lets you use the other Docker post-processors such as
[docker-push](/docs/post-processors/docker-push.html) to push the image
to a registry.
## Configuration
The configuration for this post-processor is extremely simple. At least
a repository is required. The tag is optional.
* `repository` (string) - The repository of the imported image.
* `tag` (string) - The tag for the imported image. By default this is not
set.
## Example
An example is shown below, showing only the post-processor configuration:
<pre class="prettyprint">
{
"type": "docker-import",
"repository": "mitchellh/packer",
"tag": "0.7"
}
</pre>
This example would take the image created by the Docker builder
and import it into the local Docker process with a name of `mitchellh/packer:0.7`.
Following this, you can use the
[docker-push](/docs/post-processors/docker-push.html)
post-processor to push it to a registry, if you want.
---
layout: "docs"
page_title: "Docker Push Post-Processor"
---
# Docker Push Post-Processor
Type: `docker-push`
The Docker push post-processor takes an artifact from the
[docker-import](/docs/post-processors/docker-import.html) post-processor
and pushes it to a Docker registry.
<div class="alert alert-info alert-block">
<strong>Before you use this,</strong> you must manually <code>docker login</code>
to the proper repository. A future version of Packer will automate this
for you, but for now you must manually do this.
</div>
## Configuration
This post-processor has no configuration! Simply add it to your chain
of post-processors and the image will be uploaded.
## Example
For an example of using docker-push, see the section on using
generated artifacts from the [docker builder](/docs/builders/docker.html).
......@@ -54,6 +54,8 @@
<ul>
<li><h4>Post-Processors</h4></li>
<li><a href="/docs/post-processors/docker-import.html">docker-import</a></li>
<li><a href="/docs/post-processors/docker-push.html">docker-push</a></li>
<li><a href="/docs/post-processors/vagrant.html">Vagrant</a></li>
<li><a href="/docs/post-processors/vsphere.html">vSphere</a></li>
</ul>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment