chef-provisioning-docker
chef-provisioning-docker copied to clipboard
IP Address of Docker Container?
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
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