chef-provisioning-docker icon indicating copy to clipboard operation
chef-provisioning-docker copied to clipboard

IP Address of Docker Container?

Open chrdunne opened this issue 9 years ago • 1 comments

Is it possible to get the IP address of the docker container for use in a recipe with code similar to this ec2 code?

ruby_block "print out public IP" do block do appservernode = search(:node, "name:#{appserver_instance_name}").first Chef::Log.info("Application can be accessed at http://#{appservernode['ec2']['public_ipv4']}:3001") end end

chrdunne avatar Jun 22 '15 14:06 chrdunne

Basically chef does converge docker containers same way as any other node. So, after running machine your chef server should contain node <machine_name>, and you'll be able to obtain its Ohai attributes:

ruby_block "print out public IP" do
  block do
    container = search(:node, "name:#{machine_name}").first
    Chef::Log.info("Application can be accessed at http://#{container['ipaddress']}:3001")
    Chef::Log.info("Application can be accessed at http://[#{container['ip6address']}]:3001")
  end
end

marc- avatar Jul 03 '15 08:07 marc-