@@ -254,7 +254,17 @@ def create_hosts(self, lookup):
254254 # Add the host file to be mounted
255255 write_file (hosts_file , template )
256256 return hosts_file
257-
257+
258+
259+ def generate_resolv_conf (self ):
260+ '''generate a resolv.conf file to bind to the containers.
261+ We use the template provided by scompose.
262+ '''
263+ resolv_conf = os .path .join (self .working_dir , 'resolv.conf' )
264+ if not os .path .exists (resolv_conf ):
265+ template = read_file (get_template ('resolv.conf' ))
266+ write_file (resolv_conf , template )
267+ return resolv_conf
258268
259269# Commands
260270
@@ -370,22 +380,36 @@ def down(self, names=None):
370380
371381# Create
372382
373- def create (self , names = None , writable_tmpfs = True , bridge = "10.22.0.0/16" ):
383+ def create (self , names = None ,
384+ writable_tmpfs = True ,
385+ bridge = "10.22.0.0/16" ,
386+ no_resolv = False ):
387+
374388 '''call the create function, which defaults to the command instance.create()
375389 '''
376- return self ._create (names , writable_tmpfs = writable_tmpfs )
390+ return self ._create (names ,
391+ writable_tmpfs = writable_tmpfs ,
392+ no_resolv = no_resolv )
393+
394+ def up (self , names = None ,
395+ writable_tmpfs = True ,
396+ bridge = "10.22.0.0/16" ,
397+ no_resolv = False ):
377398
378- def up (self , names = None , writable_tmpfs = True , bridge = "10.22.0.0/16" ):
379399 '''call the up function, instance.up(), which will build before if
380400 a container binary does not exist.
381401 '''
382- return self ._create (names , command = "up" , writable_tmpfs = writable_tmpfs )
402+ return self ._create (names ,
403+ command = "up" ,
404+ writable_tmpfs = writable_tmpfs ,
405+ no_resolv = no_resolv )
383406
384407 def _create (self ,
385408 names ,
386409 command = "create" ,
387410 writable_tmpfs = True ,
388- bridge = "10.22.0.0/16" ):
411+ bridge = "10.22.0.0/16" ,
412+ no_resolv = False ):
389413
390414 '''create one or more instances. "Command" determines the sub function
391415 to call for the instance, which should be "create" or "up".
@@ -400,6 +424,8 @@ def _create(self,
400424 bridge: the bridge ip address to use for networking, and generating
401425 addresses for the individual containers.
402426 see /usr/local/etc/singularity/network/00_bridge.conflist
427+ no_resolv: if True, don't create and bind a resolv.conf with Google
428+ nameservers.
403429 '''
404430 # If no names provided, we create all
405431 names = names or self .get_instance_names ()
@@ -431,9 +457,13 @@ def _create(self,
431457
432458 if do_create :
433459
434- instance .volumes .append ('%s:/etc/hosts' % hosts_file )
460+ # Generate a resolv.conf to bind to the container
461+ if not no_resolv :
462+ resolv = self .generate_resolv_conf ()
463+ instance .volumes .append ('%s:/etc/resolv.conf' % resolv )
435464
436465 # Create a hosts file for the instance based, add as volume
466+ instance .volumes .append ('%s:/etc/hosts' % hosts_file )
437467
438468 # If we get here, execute command and add to list
439469 create_func = getattr (instance , command )
0 commit comments