Docker labels

24 views
Skip to first unread message

Nicholas Bayle

unread,
Mar 18, 2019, 2:22:08 PM3/18/19
to packe...@googlegroups.com
I'm new to docker, so maybe this is just my ignorance, but does adding docker labels actually work with packer?

  9   "builders": [{
 10     "type": "docker",
 11     "image": "ubuntu:18.04",
 12     "export_path": "output-docker/akm-{{user `akm_version`}}-u{{user `u_version`}}-{{user `build_stamp`}}.tar",
 13     "changes": [
 14       "USER admin",
 15       "EXPOSE 6000 6001 6002 6003 5696",
 16       "LABEL com.townsend.version=1.0"
 17     ]
 18   }],


The resulting image has no labels.

docker ps --format "table {{.ID}}\t{{.Labels}}"
CONTAINER ID        LABELS
11b32092d884

Nick

Rickard von Essen

unread,
Mar 19, 2019, 3:54:34 AM3/19/19
to packe...@googlegroups.com
docker ps shows the running Docker containers

You should use:
docker inspect <image> --format "{{ .ContainerConfig.Labels }}"

Images labels doesn't propagate from a image to a container started from it.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CAGzi4%3D4w4um12GXPUbYiT%2BtUDMCkYBTNY%2B-VHpxMmoN%3D5QFjYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Nicholas Bayle

unread,
Mar 19, 2019, 11:57:40 AM3/19/19
to packe...@googlegroups.com
I figured I was missing something like that.

That said, I get:
docker inspect --format '{{ .ContainerConfig.Labels }}' 06a7e57ba554
map[]

Here's the full output. Labels is null:
docker inspect 06a7
[
    {
        "Id": "sha256:06a7e57ba5549e6c2bd1bdbbd7ad6369bb471ee180b41e636cd2b60fc82f0f8f",
        "RepoTags": [],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "Imported from -",
        "Created": "2019-03-18T18:19:25.921251641Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "18.09.3",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 571834611,
        "VirtualSize": 571834611,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/7a747e66900365c1a537cc8d11f9b226304211c22a13fea5be57a698cd5aea1a/merged",
                "UpperDir": "/var/lib/docker/overlay2/7a747e66900365c1a537cc8d11f9b226304211c22a13fea5be57a698cd5aea1a/diff",
                "WorkDir": "/var/lib/docker/overlay2/7a747e66900365c1a537cc8d11f9b226304211c22a13fea5be57a698cd5aea1a/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:ce86195a57b0d70635318da7f6123303ab8687b688cb458a55cd24be0fc8402d"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]


Rickard von Essen

unread,
Mar 19, 2019, 2:03:56 PM3/19/19
to packe...@googlegroups.com
Sorry I pointed to the wrong Labels..

$ cat docker-label.json
{
  "builders": [
    {
      "type": "docker",
      "image": "ubuntu:16.04",
      "commit": true,
      "changes": [
        "LABEL foo=bar"
      ]
    }
  ]
}

$ packer build docker-label.json
docker output will be in this color.

==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: ubuntu:16.04
    docker: 16.04: Pulling from library/ubuntu
    docker: Digest: sha256:58d0da8bc2f434983c6ca4713b08be00ff5586eb5cdff47bcde4b2e88fd40f88
    docker: Status: Image is up to date for ubuntu:16.04
==> docker: Starting docker container...
    docker: Run command: docker run -v /Users/rickard.von.essen/.packer.d/tmp:/packer-files -d -i -t ubuntu:16.04 /bin/bash
    docker: Container ID: e231976dedf1f08ed8a7b8f85073c7f8d198d4b0ee9bcc6010df140e3b56b1a6
==> docker: Using docker communicator to connect: 172.17.0.2
==> docker: Committing the container
    docker: Image ID: sha256:f36adac65043d944f1e4f3d8764766f3238475d317785279f333838ce0e7889a
==> docker: Killing the container: e231976dedf1f08ed8a7b8f85073c7f8d198d4b0ee9bcc6010df140e3b56b1a6
Build 'docker' finished.

==> Builds finished. The artifacts of successful builds are:
--> docker: Imported Docker image: sha256:f36adac65043d944f1e4f3d8764766f3238475d317785279f333838ce0e7889a

$  docker inspect sha256:f36adac65043d944f1e4f3d8764766f3238475d317785279f333838ce0e7889a --format "{{ .Config.Labels }}"
map[foo:bar]


Nicholas Bayle

unread,
Mar 19, 2019, 2:15:55 PM3/19/19
to packe...@googlegroups.com
No dice. Is it safe to assume that "changes": [] only works with commit, not export_path?

Rickard von Essen

unread,
Mar 19, 2019, 2:26:11 PM3/19/19
to packe...@googlegroups.com
Yes, export produces a tar with the content of the file system, but nothing else, so all metadata is lost. 

Nicholas Bayle

unread,
Mar 19, 2019, 2:36:24 PM3/19/19
to packe...@googlegroups.com
Gotcha. So I'll use commit and then use the docker-save post-processor.

Thanks

Reply all
Reply to author
Forward
0 new messages