Packer provisioning docker with chef-solo gets node name not found error

I am using chef version 11.16.4 and packer v 0.7.1 with docker v1.3.0

I am having trouble getting chef-solo to run the chef-solo provisioner after it installs chef-solo.

  • Connection refused in Docker containers communicating through exposed ports
  • Getting Unsupported protocol scheme error with docker in pycharm
  • Mount point not found
  • What does --net=host option in Docker command really do?
  • Cannot reach “static-mapped” docker container from another container on the same host
  • Jenkins Pipeline & Docker Plugin - concurrent builds on unique agents
  • I am getting the following error:

    ERROR: Unable to determine node name: configure node_name or configure the system’s hostname and fqdn

    I poked around on the internet trying to figure what was happening, and this error seems rare since node_name is usually given a default value by the system, or is assigned in solo.rb, which seemed to me can not be overwritten directly in the packer config template.

    Am I doing something wrong with my packer config or is this an incompatiblity issue between chef-solo and docker provisioning?

    I am using the following packer config:

    {
        "variables": {
             "version": "",
             "base-image-version": ""
        },
        "builders":[{
             "type": "docker",
             "image": "centos:latest",
             "pull": true,
             "export_path": "zookeeper-base-{{user `version`}}.tar"
        }],
        "provisioners":[
             {
             "type": "chef-solo",
             "cookbook_paths": ["../chef-simple/cookbooks"],
             "install_command":"curl -L https://www.opscode.com/chef/install.sh | bash",
             "execute_command":"chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
             "run_list":["recipe[zookeeper::install]"],
             "json":{"node_name":"zookeeper-box","env_name":"dev","ip":"10.10.10.10"},
             "prevent_sudo":true
        }],
        "post-processors": [{
             "type": "docker-import",
             "repository": "ed-sullivan/zookeeper-base",
             "tag": "{{user `version`}}"
        }]
    }
    

  • In Influxdb, I cannot retrieve correct values in time range
  • Spring-agent: Error opening zip file or JAR manifest missing
  • docker unable to compile program (possibly undefied macro AC_MSG_ERROR)
  • libGL error: failed to load driver swrast in docker container
  • How to limit IO speed in docker with ceph rbd?
  • Enter into docker container after shell script execution is complete
  • 2 Solutions collect form web for “Packer provisioning docker with chef-solo gets node name not found error”

    I solved this by adding a Docker hostname to the execute_command in the json file.

    "run_command": ["-d", "--hostname=foobar", "-i", "-t", "{{.Image}}", "/bin/bash"]

    I also had to install the hostname package (I think chef uses that to look up the hostname) and the curl package.

    "inline": ["yum -y update; yum -y install curl; yum -y install hostname"]

    Hopefully that helps!

    I ended up solving this by creating a config template, that defines the node_name, and installing the chef files using the file provisioner.

    Here is the updated config

    {
        "variables": {
             "version": "0.1",
             "base-image-version": "",
             "chef_dir"          : "/tmp/packer-chef-client",
             "chef_env"          : "dev"
         },
         "builders":[{
             "type": "docker",
             "image": "centos:latest",
             "pull": true,
             "export_path": "zookeeper-base-{{user `version`}}.tar"
         }],
         "provisioners":[
             { "type": "shell", "inline": [ "mkdir -p {{user `chef_dir`}}", "yum install -y tar" ] },
             { "type": "file",  "source": "../chef/cookbooks",       "destination": "{{user `chef_dir`}}" },
             {
             "type": "chef-solo",
             "install_command":"curl -L https://www.opscode.com/chef/install.sh | bash",
             "execute_command":"chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
             "run_list":["recipe[zookeeper::install]"],
             "prevent_sudo":true,
             "config_template":"./solo.rb.template"
         }],
    
    }
    

    and the corresponding config template file

    log_level   :info
    log_location    STDOUT
    local_mode  true
    ssl_verify_mode verify_peer
    role_path         "{{user `chef_dir`}}/roles"
    data_bag_path     "{{user `chef_dir`}}/data_bags"
    environment_path  "{{user `chef_dir`}}/environments"
    cookbook_path     [ "{{user `chef_dir`}}/cookbooks" ]
    node_name         "packer-docker-build"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.