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.

  • java.net.InetAddress java class doesn't resolve IP on Alpine Docker container
  • Privileges in an Ubuntu Docker container after USER statement in Dockerfile
  • docker swarm port publishing not mapping
  • Set up mapping in Elasticsearch during Docker run
  • How does one use Apache in a Docker Container and write nothing to disk (all logs to STDIO / STDERR)?
  • How to monitor Nodejs app running on Kubernetes
  • 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`}}"
        }]
    }
    

  • How do you list containers in Docker.io?
  • Nginx and uwsgi connection refused when placed in separate docker containers
  • Link Docker Container across the Host
  • tunnel ssh from another pc to docker
  • Setting PYTHONPATH in Ubuntu 16.04 for a Docker image to run properly
  • How to access to docker config file in S3 bucket from Elastic Beanstalk instance
  • 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.