'Run a one-off command in an ephemeral app container.'

def run(self, user, command):

    if (not settings.SSH_PRIVATE_KEY):
        raise EnvironmentError(u'Support    for    admin    commands    is    not    configured')
    if (self.release_set.latest().build is None):
        raise EnvironmentError(u'No    build    associated    with    this    release    to    run    this    command')
    msg = u"{}    runs    '{}'".format(user.username, command)
    log_event(self, msg)
    c_num = (max(([c.num for c in self.container_set.filter(type=u'run')] or [0])) + 1)
    c = Container.objects.create(owner=self.owner, app=self, release=self.release_set.latest(), type=u'run', num=c_num)
    image = c.release.image
    def _has_hostname(image):
        (repo, tag) = dockerutils.parse_repository_tag(image)
        return (True if ((u'/' in repo) and (u'.' in repo.split(u'/')[0])) else False)
    if (not _has_hostname(image)):
        image = u'{}:{}/{}'.format(settings.REGISTRY_HOST, settings.REGISTRY_PORT, image)
    escaped_command = command.replace(u"'", u"'\\''")
    return c.run(escaped_command)
