JavaScriptをがんばるブログ

React,OSS,ソフトウェア開発が中心のブログです👨‍💻

packerでdockerイメージbuild中にaptエラー

技術メモです。

環境

  • docker 1.12.3
  • packer 0.10.0
  • OSX 10.11.6

packer設定ファイル

// packer.json
{
    "variables": {
        "docker_image": "ubuntu"
    },
    "builders": [{
        "type": "docker",
        "image": "{{user `docker_image`}}",
        "commit": "true"
    }],
    "provisioners": [{
        "type": "shell",
        "inline": [
            "apt-get -y update",
            "apt-get -y install ansible"
        ]
    },
    {
        "type": "ansible-local",
        "playbook_file": "playbooks/main.yml"
    }]
}

エラー内容

packer build packer.jsonコマンド実行後以下のエラーが発生。

    docker: Get:30 http://archive.ubuntu.com/ubuntu xenial/main amd64 ieee-data all 20150531.1 [830 kB]
    docker: Err:30 http://archive.ubuntu.com/ubuntu xenial/main amd64 ieee-data all 20150531.1
    docker: Connection failed [IP: 91.189.88.162 80]
    docker: Get:31 http://archive.ubuntu.com/ubuntu xenial/main amd64 python-netaddr all 0.7.18-1 [174 kB]
    docker: Get:32 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 ansible all 2.0.0.2-2ubuntu1 [1016 kB]
    docker: Get:33 http://archive.ubuntu.com/ubuntu xenial/universe amd64 python-selinux amd64 2.4-3build2 [173 kB]
    docker: Fetched 9197 kB in 13min 20s (11.5 kB/s)
    docker: E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/i/ieee-data/ieee-data_20150531.1_all.deb  Connection failed [IP: 91.189.88.162 80]
    docker:
    docker: E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
==> docker: Killing the container: fbfe4d57f05a373ffd95ff2c68bae86a8d03924c7181f4138177959c561f1e3e
Build 'docker' errored: Script exited with non-zero exit status: 100

解決プロセス

エラーメッセージでググりstackoverflowの記事を参照。 aptのキャッシュが原因というようなレスがあったのでもう一度packer build packer.jsonコマンドを実行したら発生しなくなった。

askubuntu.com

まとめ

packerとは関係の無いubuntu(apt)の問題だった。
以下packer buildコマンドのマニュアルページには-on-error=cleanup (default)
build中エラーが発生した場合は作業過程のイメージは捨てられると書いてあるので、
過去にbuild成功した時のaptキャッシュが使用されたのでないかと思う。

www.packer.io