'Generate and return the docker command to execute'

def docker_cmd(self, image, env_override=None, volumes=None):

    if (volumes is None):
        volumes = []
    env = self._get_env_for_run(env_override)
    import_volume_def = self._get_import_volume_for_run()
    env_str = '    '.join((('-e    "%s=%s"' % (key, item)) for (key, item) in env.items()))
    volume_str = ('    '.join((('-v    "%s"' % volume) for volume in volumes)) if self.use_volumes else '')
    import_volume_str = ('-v    "{import_volume}"'.format(import_volume=import_volume_def) if import_volume_def else '')
    name = None
    command = self.attr.viz_config.get('docker', 'command')
    command_inject = self.attr.viz_config.get('docker', 'command_inject')
    if ('--name' not in command_inject):
        name = self._get_name_for_run()
    command = command.format(docker_args='run    {command_inject}    {name}    {environment}    -d    -P    {import_volume_str}    {volume_str}    {image}')
    command = command.format(command_inject=command_inject, name=(('--name=%s' % name) if (name is not None) else ''), environment=env_str, import_volume_str=import_volume_str, volume_str=volume_str, image=image)
    return command
