コード例 #1
0
ファイル: docker_actions.py プロジェクト: swipswaps/stakkr
def get_client():
    """Return the client or initialize it."""
    if 'client' not in __st__:
        from docker import client
        __st__['client'] = client.from_env()

    return __st__['client']
コード例 #2
0
    def __init__(
        self,
        check,
        env,
        base_package=None,
        config=None,
        env_vars=None,
        metadata=None,
        agent_build=None,
        api_key=None,
        python_version=DEFAULT_PYTHON_VERSION,
    ):
        self.docker_client = docker_client.from_env()
        self.check = check
        self.env = env
        self.env_vars = env_vars or {}
        self.base_package = base_package
        self.config = config or {}
        self.metadata = metadata or {}
        self.agent_build = agent_build
        self.api_key = api_key or FAKE_API_KEY
        self.python_version = python_version or DEFAULT_PYTHON_VERSION

        self._agent_version = self.metadata.get('agent_version')
        self.container_name = 'dd_{}_{}'.format(self.check, self.env)
        self.config_dir = locate_config_dir(check, env)
        self.config_file = locate_config_file(check, env)
        self.config_file_name = config_file_name(self.check)

        if self.agent_build and 'py' not in self.agent_build:
            self.agent_build = '{}-py{}'.format(self.agent_build,
                                                self.python_version)

        if self.agent_build and self.metadata.get('use_jmx', False):
            self.agent_build = '{}-jmx'.format(self.agent_build)
コード例 #3
0
def get_client():
    """Return the client or initialize it."""
    if 'client' not in __st__:
        from docker import client
        __st__['client'] = client.from_env()

    return __st__['client']
コード例 #4
0
ファイル: docker.py プロジェクト: Yupeek/maiev
 def setup(self):
     docker_cfg = self.container.config.get('DOCKER')
     if docker_cfg:
         self.client = client.Client(**docker_cfg)
     else:
         self.client = client.from_env()
     self.client.info()
     self.event_handlers = []
コード例 #5
0
 def start_proxy(self, outpost: Outpost) -> Container:
     """Start proxy container based on outpost created"""
     client: DockerClient = from_env()
     container = client.containers.run(
         image=self.get_container_image("ghcr.io/goauthentik/dev-proxy"),
         detach=True,
         network_mode="host",
         environment={
             "AUTHENTIK_HOST": self.live_server_url,
             "AUTHENTIK_TOKEN": outpost.token.key,
         },
     )
     return container
コード例 #6
0
ファイル: __init__.py プロジェクト: bcicen/docker-rerun
    def __init__(self, container_id, pretty_print=True):
        from docker import client, errors
        from docker_replay.parser import ConfigParser

        self.pretty_print = pretty_print

        c = client.from_env(version='auto')

        try:
            inspect = c.api.inspect_container(container_id)
            self.parser = ConfigParser(inspect)
        except errors.NotFound:
            print('no such container: %s' % container_id)
            sys.exit(1)
コード例 #7
0
ファイル: __init__.py プロジェクト: xestyle/docker-replay
    def __init__(self, container_id, pretty_print=True):
        from docker import client, errors
        from docker_replay.parser import ConfigParser

        self.pretty_print = pretty_print

        c = client.from_env(version='auto')

        try:
            inspect = c.api.inspect_container(container_id)
            self.parser = ConfigParser(inspect)
        except errors.NotFound:
            print('no such container: %s' % container_id)
            sys.exit(1)
コード例 #8
0
 def start_proxy(self, outpost: Outpost) -> Container:
     """Start proxy container based on outpost created"""
     client: DockerClient = from_env()
     container = client.containers.run(
         image=f"beryju/authentik-proxy:{__version__}",
         detach=True,
         network_mode="host",
         auto_remove=True,
         environment={
             "AUTHENTIK_HOST": self.live_server_url,
             "AUTHENTIK_TOKEN": outpost.token.key,
         },
     )
     return container
コード例 #9
0
def runContainer():
    mydocker = client.from_env()

    container = mydocker.containers.run('registry.cn-hangzhou.aliyuncs.com/edge_node/eureka:latest',
                                         detach=True,name="eureka",ports={"10000/tcp" : [10000]} ,network_mode="zhuanyong")

    container_list = mydocker.containers.list();
    container = mydocker.containers.get("eureka")
    if container in container_list:
        if container.status == "running":
            print("create success")
            print(container.name+" "+container.id+" "+container.short_id+" "+container.status)
    else:
        print("create failure")
コード例 #10
0
ファイル: container.py プロジェクト: uranusbeam/bit-dagster
def run_serialized_container_command(image, command, volumes):
    try:
        from docker.client import from_env
    except ImportError:
        warnings.warn(
            "Cannot load docker environment without the python package docker. Ensure that dagster[docker] or the python package docker is installed."
        )
        raise

    client = from_env()
    client.containers.run(image,
                          command=command,
                          detach=False,
                          volumes=volumes,
                          auto_remove=True)
コード例 #11
0
class JobExecutor:
    docker_client = dockerClient.from_env()
    producer = KafkaProducer(
        **kafka_params,
        value_serializer=lambda v: json.dumps(v).encode('utf-8'))

    def startContainer(self, feedName):
        container = self.docker_client.containers.get(feedName)
        container.start()

    def publishUrl(self, feedName, url):
        item = {"url": url, "type": feedName}
        self.producer.send(topic="worker-queue".format(name=feedName),
                           value=item,
                           key=bytes(url, 'utf-8'))
コード例 #12
0
ファイル: container.py プロジェクト: spencer-zepelin/dagster
def run_serialized_container_command(image, command, volumes):
    try:
        from docker.client import from_env

        client = from_env()
        byte_stream = client.containers.run(
            image, command=command, volumes=volumes, auto_remove=False,
        )

        # Decode to string, split by newlines, and filter for any empty strings
        lines = list(filter(None, byte_stream.decode('utf-8').split("\n")))
        return lines
    except ImportError:
        warnings.warn(
            "Cannot load docker environment without the python package docker. Ensure that dagster[docker] or the python package docker is installed."
        )
        raise
コード例 #13
0
ファイル: container.py プロジェクト: spencer-zepelin/dagster
def run_detached_container_command(image, command, volumes, output_file):

    try:
        from docker.client import from_env

        client = from_env()

        # This is currently blocking. Has to be updated to run in detached mode. The problem
        # is knowing when the file is ready to be read from.
        client.containers.run(image, command=command, volumes=volumes, auto_remove=False)

        for message in ipc_read_event_stream(output_file):
            yield message

    except ImportError:
        warnings.warn(
            "Cannot load docker environment without the python package docker. Ensure that dagster[docker] or the python package docker is installed."
        )
        raise
コード例 #14
0
    def setUpClass():
        """Clean containers and services directory"""
        from docker import client
        from docker.errors import NotFound
        cts = client.from_env().containers.list(all=True)
        for ct in cts:
            try:
                ct.stop()
                ct.remove(v=True, force=True)
            except NotFound:
                pass

        cli = CliTest()

        for service in ['db', 'databases', 'emails', 'php']:
            rmtree(BASE_DIR + '/static/services/' + service,
                   ignore_errors=True)
        exec_cmd(cli.cmd_base + ['services-add', 'php'])
        exec_cmd(cli.cmd_base + ['services-add', 'emails'])
コード例 #15
0
ファイル: docker.py プロジェクト: addisonj/integrations-core
def run_in_container(container_name, command, check=True, interactive=False):
    """Runs a command in the given container. This is useful for WaitFor conditions in `docker_run`

    :param container_name: The name of the container
    :param command: command line to run in the container
    :param check: Whether or not to raise an exception on non-zero exit codes. Default: ``True``
    :param interactive: Attach to stdin. Default: ``False``
    """
    client = docker_client.from_env()
    container = client.containers.get(container_name)
    if not container:
        raise Exception("Could not find container {}".format(container_name))
    try:
        command_line = ' '.join(command) if isinstance(command,
                                                       list) else command
    except TypeError as e:
        raise e
    result = container.exec_run(command_line, stdin=interactive)
    if check and result.exit_code != 0:
        raise Exception(result.output)
    return result
コード例 #16
0
ファイル: DockerClient.py プロジェクト: denysom/APTF
class DockerClient(object):

    _client = client.from_env()

    def stop_all_running_containers(self):
        for container in self._client.containers.list():
            container.stop()

    def list_all_images(self):
        images = list()
        for image in self._client.images.list(all=True):
            images.extend(image.tags)
        return images

    def get_image(self, name):
        try:
            self._client.images.get(name)
        except errors.ImageNotFound:
            pass
        except errors.APIError:
            pass

    def remove_image(self, image_id):
        self._client.images.remove(image_id, force=True)
コード例 #17
0
ファイル: session.py プロジェクト: sourcesimian/vpn-porthole
 def __init__(self, settings):
     self.__settings = settings
     self.__sc = SystemCalls(self._name(), self.__settings)
     self.__dc = from_env(environment=self.__sc.get_docker_env()).api
コード例 #18
0
import io
import os
import sys
import unittest
import docker_clean
from contextlib import redirect_stdout
from click.testing import CliRunner
from docker.errors import NotFound
from docker import client
DOCKER_CLIENT = client.from_env()
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, BASE_DIR + '/../')


class DockerCleanTest(unittest.TestCase):
    def test_remove_containers_empty(self):
        clean_cts()

        fake_file = io.StringIO()
        with redirect_stdout(fake_file):
            docker_clean.remove_containers(True)
        res = fake_file.getvalue()
        self.assertEqual('No exited container to remove', res.strip())

    def test_remove_containers_pretend(self):
        clean_cts()
        clean_images()

        DOCKER_CLIENT.containers.run('hello-world', remove=False)
        num_containers = len(DOCKER_CLIENT.containers.list(all=True))
        fake_file = io.StringIO()
コード例 #19
0
#!/usr/bin/env python
# coding: utf-8
"""
Docker Clean command.

Clean unused containers, images, volumes and networks.
That saves a lot of space ...
"""

import sys
import click
import humanfriendly
from docker import client
DOCKER_CLIENT = client.from_env(timeout=360)


@click.command(help="""Clean Docker containers, images, volumes and networks
that are not in use""", name="docker-clean")
@click.version_option('1.0.2')
@click.option('--force', '-f', help="Do it", is_flag=True)
@click.option('--containers/--no-containers', '-c/', help="Remove containers", is_flag=True, default=True)
@click.option('--images/--no-images', '-i/', help="Remove images", is_flag=True, default=True)
@click.option('--volumes/--no-volumes', '-V/', help="Remove volumes", is_flag=True, default=True)
@click.option('--networks/--no-networks', '-n/', help="Remove networks", is_flag=True, default=True)
def clean(
        force: bool = False,
        containers: bool = True,
        images: bool = True,
        volumes: bool = True,
        networks: bool = True):
    """See command help."""
コード例 #20
0
ファイル: docker.py プロジェクト: addisonj/integrations-core
def get_container_ip(container_id_or_name):
    """Get a Docker container's IP address from its id or name."""
    client = docker_client.from_env()
    inspect = client.api.inspect_container(container_id_or_name)
    return inspect["NetworkSettings"]["Networks"]["compose_default"][
        "IPAddress"]
コード例 #21
0
ファイル: qassembler.py プロジェクト: jagyugyaerik/qassembler
def init_docker_client() -> client:
    return client.from_env()
コード例 #22
0
from docker import client
import os
import sys

mydocker = client.from_env()

net = mydocker.networks.get("host")
print(net.containers)
コード例 #23
0
ファイル: app.py プロジェクト: lethe3000/v4docker
 def __init__(self):
     self.docker_client = client.from_env()
     self._init_screen()
     self._init_widgets()