LoginSignup
5
5

More than 5 years have passed since last update.

Packer buildでDocker HubにDocker Imageを保存するやいなやpullしてcowsayする

Last updated at Posted at 2015-09-09

Packer buildでDocker HubにDocker Imageを保存するやいなやpullしてcowsayします

サンプル

仕様

Base Image: ubuntu:trusty - Docker Hub

Base Imageをpullする

$ docker pull ubuntu:trusty

template.json

{
    "builders":[{
        "type": "docker",
        "image": "ubuntu:trusty",
        "commit": true
    }],

    "provisioners":[
    {
        "type": "shell",
        "inline": [
            "apt-get -y update",
            "apt-get install -y cowsay"
        ]
    }
    ],

    "post-processors": [
        [
            {
                "type": "docker-tag",
                "repository": "tbpgr/cowsay",
                "tag": "0.0.1"
            },
            "docker-push"
        ]
    ]
}

Packer buildでDocker HubにImageをpush

$ packer build template.json

pushされたImageをDocker Hub上で確認

packer_docker1.png

Docker Hubに保存したImageを検索します

$ docker search tbpgr/cowsay
NAME            DESCRIPTION   STARS     OFFICIAL   AUTOMATED
tbpgr/cowsay                 0   

ローカル環境のDocker Imageを一度削除します

pullの検証をするため、Docker Imageを1回削除します

$ docker rmi tbpgr/cowsay:0.0.1
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

Docker Hubに保存したImageをpullします

$ docker pull tbpgr/cowsay:0.0.1
0.0.1: Pulling from tbpgr/cowsay
# 中略
Status: Downloaded newer image for tbpgr/cowsay:0.0.1
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
tbpgr/cowsay       0.0.1               8cb354c0a903        12 minutes ago      210.5 MB

Docker Hubから取得した自作Docker Imageを実行します

$ docker run -i -t tbpgr/cowsay:0.0.1 /usr/games/cowsay hoge ______
< hoge >
 ------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5