* Create a new {@link DockerContainerLocation} wrapping a machine from the host's {@link JcloudsLocation}.
*/
@Override
public DockerContainerLocation createLocation(Map flags) {
DockerHost dockerHost = getDockerHost();
DockerHostLocation host = dockerHost.getDynamicLocation();
SubnetTier subnetTier = dockerHost.getSubnetTier();
// Configure the container options based on the host and the running entity
DockerTemplateOptions options = getDockerTemplateOptions();
// put these fields on the location so it has the info it needs to create the subnet
Map<?, ?> dockerFlags = MutableMap.<Object, Object>builder()
.put(JcloudsLocationConfig.TEMPLATE_BUILDER, new PortableTemplateBuilder().options(options))
.put(JcloudsLocationConfig.IMAGE_ID, getConfig(DOCKER_IMAGE_ID))
.put(JcloudsLocationConfig.HARDWARE_ID, getConfig(DOCKER_HARDWARE_ID))
.put(LocationConfigKeys.USER, "root")
.put(LocationConfigKeys.PASSWORD, getConfig(DOCKER_PASSWORD))
.put(SshTool.PROP_PASSWORD, getConfig(DOCKER_PASSWORD))
.put(LocationConfigKeys.PRIVATE_KEY_DATA, null)
.put(LocationConfigKeys.PRIVATE_KEY_FILE, null)
.put(CloudLocationConfig.WAIT_FOR_SSHABLE, false)
.put(JcloudsLocationConfig.INBOUND_PORTS, getRequiredOpenPorts(getRunningEntity()))
.put(JcloudsLocation.USE_PORT_FORWARDING, true)
.put(JcloudsLocation.PORT_FORWARDER, subnetTier.getPortForwarderExtension())
.put(JcloudsLocation.PORT_FORWARDING_MANAGER, subnetTier.getPortForwardManager())
.put(JcloudsPortforwardingSubnetLocation.PORT_FORWARDER, subnetTier.getPortForwarder())
.put(SubnetTier.SUBNET_CIDR, Cidr.CLASS_B)
.build();
try {
// Create a new container using jclouds Docker driver
JcloudsSshMachineLocation container = host.getJcloudsLocation().obtain(dockerFlags);
setAttribute(CONTAINER_ID, container.getNode().getId());
// If Weave is enabled, attach to the network
if (getConfig(DockerInfrastructure.WEAVE_ENABLED)) {
WeaveContainer weave = Entities.attributeSupplierWhenReady(dockerHost, WeaveContainer.WEAVE_CONTAINER).get();