Created
June 15, 2018 10:59
-
-
Save minrk/23d0826ab30e778f8d91a5304bb6b35c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import socket\ns = socket.socket()", | |
"execution_count": 11, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s.bind(('127.0.0.1', 0))", | |
"execution_count": 12, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "s.getsockname()", | |
"execution_count": 14, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 14, | |
"data": { | |
"text/plain": "('127.0.0.1', 58938)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "port = s.getsockname()[1]\ns.close()\nport", | |
"execution_count": 16, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 16, | |
"data": { | |
"text/plain": "58938" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import docker", | |
"execution_count": 17, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "client = docker.from_env(version='auto')\nclient.containers.run?", | |
"execution_count": 33, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/plain": "\u001b[1;31mSignature:\u001b[0m \u001b[0mclient\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcontainers\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcommand\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstdout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstderr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mremove\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;31mDocstring:\u001b[0m\nRun a container. By default, it will wait for the container to finish\nand return its logs, similar to ``docker run``.\n\nIf the ``detach`` argument is ``True``, it will start the container\nand immediately return a :py:class:`Container` object, similar to\n``docker run -d``.\n\nExample:\n Run a container and get its output:\n\n >>> import docker\n >>> client = docker.from_env()\n >>> client.containers.run('alpine', 'echo hello world')\n b'hello world\\n'\n\n Run a container and detach:\n\n >>> container = client.containers.run('bfirsh/reticulate-splines',\n detach=True)\n >>> container.logs()\n 'Reticulating spline 1...\\nReticulating spline 2...\\n'\n\nArgs:\n image (str): The image to run.\n command (str or list): The command to run in the container.\n auto_remove (bool): enable auto-removal of the container on daemon\n side when the container's process exits.\n blkio_weight_device: Block IO weight (relative device weight) in\n the form of: ``[{\"Path\": \"device_path\", \"Weight\": weight}]``.\n blkio_weight: Block IO weight (relative weight), accepts a weight\n value between 10 and 1000.\n cap_add (list of str): Add kernel capabilities. For example,\n ``[\"SYS_ADMIN\", \"MKNOD\"]``.\n cap_drop (list of str): Drop kernel capabilities.\n cpu_count (int): Number of usable CPUs (Windows only).\n cpu_percent (int): Usable percentage of the available CPUs\n (Windows only).\n cpu_period (int): The length of a CPU period in microseconds.\n cpu_quota (int): Microseconds of CPU time that the container can\n get in a CPU period.\n cpu_shares (int): CPU shares (relative weight).\n cpuset_cpus (str): CPUs in which to allow execution (``0-3``,\n ``0,1``).\n cpuset_mems (str): Memory nodes (MEMs) in which to allow execution\n (``0-3``, ``0,1``). Only effective on NUMA systems.\n detach (bool): Run container in the background and return a\n :py:class:`Container` object.\n device_cgroup_rules (:py:class:`list`): A list of cgroup rules to\n apply to the container.\n device_read_bps: Limit read rate (bytes per second) from a device\n in the form of: `[{\"Path\": \"device_path\", \"Rate\": rate}]`\n device_read_iops: Limit read rate (IO per second) from a device.\n device_write_bps: Limit write rate (bytes per second) from a\n device.\n device_write_iops: Limit write rate (IO per second) from a device.\n devices (:py:class:`list`): Expose host devices to the container,\n as a list of strings in the form\n ``<path_on_host>:<path_in_container>:<cgroup_permissions>``.\n\n For example, ``/dev/sda:/dev/xvda:rwm`` allows the container\n to have read-write access to the host's ``/dev/sda`` via a\n node named ``/dev/xvda`` inside the container.\n dns (:py:class:`list`): Set custom DNS servers.\n dns_opt (:py:class:`list`): Additional options to be added to the\n container's ``resolv.conf`` file.\n dns_search (:py:class:`list`): DNS search domains.\n domainname (str or list): Set custom DNS search domains.\n entrypoint (str or list): The entrypoint for the container.\n environment (dict or list): Environment variables to set inside\n the container, as a dictionary or a list of strings in the\n format ``[\"SOMEVARIABLE=xxx\"]``.\n extra_hosts (dict): Addtional hostnames to resolve inside the\n container, as a mapping of hostname to IP address.\n group_add (:py:class:`list`): List of additional group names and/or\n IDs that the container process will run as.\n healthcheck (dict): Specify a test to perform to check that the\n container is healthy.\n hostname (str): Optional hostname for the container.\n init (bool): Run an init inside the container that forwards\n signals and reaps processes\n init_path (str): Path to the docker-init binary\n ipc_mode (str): Set the IPC mode for the container.\n isolation (str): Isolation technology to use. Default: `None`.\n labels (dict or list): A dictionary of name-value labels (e.g.\n ``{\"label1\": \"value1\", \"label2\": \"value2\"}``) or a list of\n names of labels to set with empty values (e.g.\n ``[\"label1\", \"label2\"]``)\n links (dict or list of tuples): Either a dictionary mapping name\n to alias or as a list of ``(name, alias)`` tuples.\n log_config (dict): Logging configuration, as a dictionary with\n keys:\n\n - ``type`` The logging driver name.\n - ``config`` A dictionary of configuration for the logging\n driver.\n\n mac_address (str): MAC address to assign to the container.\n mem_limit (int or str): Memory limit. Accepts float values\n (which represent the memory limit of the created container in\n bytes) or a string with a units identification char\n (``100000b``, ``1000k``, ``128m``, ``1g``). If a string is\n specified without a units character, bytes are assumed as an\n intended unit.\n mem_swappiness (int): Tune a container's memory swappiness\n behavior. Accepts number between 0 and 100.\n memswap_limit (str or int): Maximum amount of memory + swap a\n container is allowed to consume.\n mounts (:py:class:`list`): Specification for mounts to be added to\n the container. More powerful alternative to ``volumes``. Each\n item in the list is expected to be a\n :py:class:`docker.types.Mount` object.\n name (str): The name for this container.\n nano_cpus (int): CPU quota in units of 1e-9 CPUs.\n network (str): Name of the network this container will be connected\n to at creation time. You can connect to additional networks\n using :py:meth:`Network.connect`. Incompatible with\n ``network_mode``.\n network_disabled (bool): Disable networking.\n network_mode (str): One of:\n\n - ``bridge`` Create a new network stack for the container on\n on the bridge network.\n - ``none`` No networking for this container.\n - ``container:<name|id>`` Reuse another container's network\n stack.\n - ``host`` Use the host network stack.\n\n Incompatible with ``network``.\n oom_kill_disable (bool): Whether to disable OOM killer.\n oom_score_adj (int): An integer value containing the score given\n to the container in order to tune OOM killer preferences.\n pid_mode (str): If set to ``host``, use the host PID namespace\n inside the container.\n pids_limit (int): Tune a container's pids limit. Set ``-1`` for\n unlimited.\n platform (str): Platform in the format ``os[/arch[/variant]]``.\n Only used if the method needs to pull the requested image.\n ports (dict): Ports to bind inside the container.\n\n The keys of the dictionary are the ports to bind inside the\n container, either as an integer or a string in the form\n ``port/protocol``, where the protocol is either ``tcp`` or\n ``udp``.\n\n The values of the dictionary are the corresponding ports to\n open on the host, which can be either:\n\n - The port number, as an integer. For example,\n ``{'2222/tcp': 3333}`` will expose port 2222 inside the\n container as port 3333 on the host.\n - ``None``, to assign a random host port. For example,\n ``{'2222/tcp': None}``.\n - A tuple of ``(address, port)`` if you want to specify the\n host interface. For example,\n ``{'1111/tcp': ('127.0.0.1', 1111)}``.\n - A list of integers, if you want to bind multiple host ports\n to a single container port. For example,\n ``{'1111/tcp': [1234, 4567]}``.\n\n privileged (bool): Give extended privileges to this container.\n publish_all_ports (bool): Publish all ports to the host.\n read_only (bool): Mount the container's root filesystem as read\n only.\n remove (bool): Remove the container when it has finished running.\n Default: ``False``.\n restart_policy (dict): Restart the container when it exits.\n Configured as a dictionary with keys:\n\n - ``Name`` One of ``on-failure``, or ``always``.\n - ``MaximumRetryCount`` Number of times to restart the\n container on failure.\n\n For example:\n ``{\"Name\": \"on-failure\", \"MaximumRetryCount\": 5}``\n\n security_opt (:py:class:`list`): A list of string values to\n customize labels for MLS systems, such as SELinux.\n shm_size (str or int): Size of /dev/shm (e.g. ``1G``).\n stdin_open (bool): Keep ``STDIN`` open even if not attached.\n stdout (bool): Return logs from ``STDOUT`` when ``detach=False``.\n Default: ``True``.\n stderr (bool): Return logs from ``STDERR`` when ``detach=False``.\n Default: ``False``.\n stop_signal (str): The stop signal to use to stop the container\n (e.g. ``SIGINT``).\n storage_opt (dict): Storage driver options per container as a\n key-value mapping.\n stream (bool): If true and ``detach`` is false, return a log\n generator instead of a string. Ignored if ``detach`` is true.\n Default: ``False``.\n sysctls (dict): Kernel parameters to set in the container.\n tmpfs (dict): Temporary filesystems to mount, as a dictionary\n mapping a path inside the container to options for that path.\n\n For example:\n\n .. code-block:: python\n\n {\n '/mnt/vol2': '',\n '/mnt/vol1': 'size=3G,uid=1000'\n }\n\n tty (bool): Allocate a pseudo-TTY.\n ulimits (:py:class:`list`): Ulimits to set inside the container, as\n a list of dicts.\n user (str or int): Username or UID to run commands as inside the\n container.\n userns_mode (str): Sets the user namespace mode for the container\n when user namespace remapping option is enabled. Supported\n values are: ``host``\n volume_driver (str): The name of a volume driver/plugin.\n volumes (dict or list): A dictionary to configure volumes mounted\n inside the container. The key is either the host path or a\n volume name, and the value is a dictionary with the keys:\n\n - ``bind`` The path to mount the volume inside the container\n - ``mode`` Either ``rw`` to mount the volume read/write, or\n ``ro`` to mount it read-only.\n\n For example:\n\n .. code-block:: python\n\n {'/home/user1/': {'bind': '/mnt/vol2', 'mode': 'rw'},\n '/var/www': {'bind': '/mnt/vol1', 'mode': 'ro'}}\n\n volumes_from (:py:class:`list`): List of container names or IDs to\n get volumes from.\n working_dir (str): Path to the working directory.\n runtime (str): Runtime to use with this container.\n\nReturns:\n The container logs, either ``STDOUT``, ``STDERR``, or both,\n depending on the value of the ``stdout`` and ``stderr`` arguments.\n\n ``STDOUT`` and ``STDERR`` may be read only if either ``json-file``\n or ``journald`` logging driver used. Thus, if you are using none of\n these drivers, a ``None`` object is returned instead. See the\n `Engine API documentation\n <https://docs.docker.com/engine/api/v1.30/#operation/ContainerLogs/>`_\n for full details.\n\n If ``detach`` is ``True``, a :py:class:`Container` object is\n returned instead.\n\nRaises:\n :py:class:`docker.errors.ContainerError`\n If the container exits with a non-zero exit code and\n ``detach`` is ``False``.\n :py:class:`docker.errors.ImageNotFound`\n If the specified image does not exist.\n :py:class:`docker.errors.APIError`\n If the server returns an error.\n\u001b[1;31mFile:\u001b[0m ~/conda/lib/python3.6/site-packages/docker/models/containers.py\n\u001b[1;31mType:\u001b[0m method\n" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "port", | |
"execution_count": 34, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 34, | |
"data": { | |
"text/plain": "58938" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Create the dictionary for docker that forwards our port on the host to the same port in the container" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "port_dict = {'%i/tcp' % port : port}\nport_dict", | |
"execution_count": 35, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 35, | |
"data": { | |
"text/plain": "{'58938/tcp': 58938}" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Start the container. `detach=True` allows this to return immediately while the container is still running." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "container = client.containers.run(\n \"jupyter/base-notebook\",\n command=[\"jupyter\", \"notebook\", \"--ip=0.0.0.0\", \"--port=%i\" % port],\n ports=port_dict,\n detach=True,\n remove=True,\n)\ncontainer.attrs", | |
"execution_count": 39, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 39, | |
"data": { | |
"text/plain": "{'Id': '53b926531746b593163047adb2d551299f21012d8247776a4ddc5d528f5a87e5',\n 'Created': '2018-06-15T10:50:58.356344753Z',\n 'Path': 'tini',\n 'Args': ['-g', '--', 'jupyter', 'notebook', '--ip=0.0.0.0', '--port=58938'],\n 'State': {'Status': 'created',\n 'Running': False,\n 'Paused': False,\n 'Restarting': False,\n 'OOMKilled': False,\n 'Dead': False,\n 'Pid': 0,\n 'ExitCode': 0,\n 'Error': '',\n 'StartedAt': '0001-01-01T00:00:00Z',\n 'FinishedAt': '0001-01-01T00:00:00Z'},\n 'Image': 'sha256:4d1850bf13b84d11db172e66449cabd718df7d9e609e7ef40354946993581efb',\n 'ResolvConfPath': '',\n 'HostnamePath': '',\n 'HostsPath': '',\n 'LogPath': '',\n 'Name': '/laughing_mccarthy',\n 'RestartCount': 0,\n 'Driver': 'overlay2',\n 'Platform': 'linux',\n 'MountLabel': '',\n 'ProcessLabel': '',\n 'AppArmorProfile': '',\n 'ExecIDs': None,\n 'HostConfig': {'Binds': None,\n 'ContainerIDFile': '',\n 'LogConfig': {'Type': 'json-file', 'Config': {}},\n 'NetworkMode': 'default',\n 'PortBindings': {'58938/tcp': [{'HostIp': '', 'HostPort': '58938'}]},\n 'RestartPolicy': {'Name': '', 'MaximumRetryCount': 0},\n 'AutoRemove': True,\n 'VolumeDriver': '',\n 'VolumesFrom': None,\n 'CapAdd': None,\n 'CapDrop': None,\n 'Dns': None,\n 'DnsOptions': None,\n 'DnsSearch': None,\n 'ExtraHosts': None,\n 'GroupAdd': None,\n 'IpcMode': 'shareable',\n 'Cgroup': '',\n 'Links': None,\n 'OomScoreAdj': 0,\n 'PidMode': '',\n 'Privileged': False,\n 'PublishAllPorts': False,\n 'ReadonlyRootfs': False,\n 'SecurityOpt': None,\n 'UTSMode': '',\n 'UsernsMode': '',\n 'ShmSize': 67108864,\n 'Runtime': 'runc',\n 'ConsoleSize': [0, 0],\n 'Isolation': '',\n 'CpuShares': 0,\n 'Memory': 0,\n 'NanoCpus': 0,\n 'CgroupParent': '',\n 'BlkioWeight': 0,\n 'BlkioWeightDevice': None,\n 'BlkioDeviceReadBps': None,\n 'BlkioDeviceWriteBps': None,\n 'BlkioDeviceReadIOps': None,\n 'BlkioDeviceWriteIOps': None,\n 'CpuPeriod': 0,\n 'CpuQuota': 0,\n 'CpuRealtimePeriod': 0,\n 'CpuRealtimeRuntime': 0,\n 'CpusetCpus': '',\n 'CpusetMems': '',\n 'Devices': None,\n 'DeviceCgroupRules': None,\n 'DiskQuota': 0,\n 'KernelMemory': 0,\n 'MemoryReservation': 0,\n 'MemorySwap': 0,\n 'MemorySwappiness': None,\n 'OomKillDisable': False,\n 'PidsLimit': 0,\n 'Ulimits': None,\n 'CpuCount': 0,\n 'CpuPercent': 0,\n 'IOMaximumIOps': 0,\n 'IOMaximumBandwidth': 0},\n 'GraphDriver': {'Data': {'LowerDir': '/var/lib/docker/overlay2/b824e3c97b4fafe4aa48f6d62730e19e6daa6abddbd324d59a0630eeeac22bb7-init/diff:/var/lib/docker/overlay2/05667eb1399d6d66f6372f897d9edebf3e073902a71e73f752844ba3438d19ac/diff:/var/lib/docker/overlay2/d5823f39e52af886171ade2255a566e7d872cdb6804d272f4551074982e92a4a/diff:/var/lib/docker/overlay2/d107b0575345e3f56c3712b862e94f943db9cfa626def1c83d8f7bdda909b26b/diff:/var/lib/docker/overlay2/c2c292d60e8cedf16e493de214b788eec7ef726f49528330954e256664059062/diff:/var/lib/docker/overlay2/7d5fb5b7ffc13480969a584f1d664e170d16f781db8368a7dc50cddc51cc287e/diff:/var/lib/docker/overlay2/59d975cfcc0618b114c574313082d1c8a08e3ad5afae9d87663f70ce971c8b6e/diff:/var/lib/docker/overlay2/f9f695ebf4b377d9f3e40b262cef08506cdca66beef9e4adcc8538290a1584c1/diff:/var/lib/docker/overlay2/9cdbb195af449cdaa984acb7607b0009b376d78fd143da291f700bd7ac358af5/diff:/var/lib/docker/overlay2/d8318b6efa7e9d55a2b4728e4e0904c9042b2b2dd69a02ad3669d10b6e5783cd/diff:/var/lib/docker/overlay2/449acd0c01f17967911b38249c4f8b9c96ffe7e0221eb0229a06f0af580529f9/diff:/var/lib/docker/overlay2/a9bc950634edfce5ae774d42834f6085a4f6adfcfd278a97f7e461388b79856e/diff:/var/lib/docker/overlay2/9068e6bd8ca13f5475ad1c126fd4952f2b369d3daf6795865431ccfb4739bcd1/diff:/var/lib/docker/overlay2/27bb5b5d3de166e8120ad20825eb8480c087edd09801b62f4d6ac6c51638969a/diff:/var/lib/docker/overlay2/2330f726c314f19d61722800572f3696e1a2e2df70994970db2b2921c05545b5/diff:/var/lib/docker/overlay2/54ee572efb2497b12025e5bae3a677a5002c08ba4204a319bf2d4530b5073eec/diff:/var/lib/docker/overlay2/582d30b95539508d5f7adbad5ac79bf4554ef641437bebe8317397bf2ad722c2/diff:/var/lib/docker/overlay2/03c130639ed4f6b742b8c7c22657391f371fff36a04215ffa68003e38edfde3c/diff:/var/lib/docker/overlay2/56ef359671bff45cab933d031c2f0d17a8d3eab31f60854356433ee53e4c903c/diff',\n 'MergedDir': '/var/lib/docker/overlay2/b824e3c97b4fafe4aa48f6d62730e19e6daa6abddbd324d59a0630eeeac22bb7/merged',\n 'UpperDir': '/var/lib/docker/overlay2/b824e3c97b4fafe4aa48f6d62730e19e6daa6abddbd324d59a0630eeeac22bb7/diff',\n 'WorkDir': '/var/lib/docker/overlay2/b824e3c97b4fafe4aa48f6d62730e19e6daa6abddbd324d59a0630eeeac22bb7/work'},\n 'Name': 'overlay2'},\n 'Mounts': [],\n 'Config': {'Hostname': '53b926531746',\n 'Domainname': '',\n 'User': '1000',\n 'AttachStdin': False,\n 'AttachStdout': False,\n 'AttachStderr': False,\n 'ExposedPorts': {'58938/tcp': {}, '8888/tcp': {}},\n 'Tty': False,\n 'OpenStdin': False,\n 'StdinOnce': False,\n 'Env': ['PATH=/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',\n 'DEBIAN_FRONTEND=noninteractive',\n 'CONDA_DIR=/opt/conda',\n 'SHELL=/bin/bash',\n 'NB_USER=jovyan',\n 'NB_UID=1000',\n 'NB_GID=100',\n 'LC_ALL=en_US.UTF-8',\n 'LANG=en_US.UTF-8',\n 'LANGUAGE=en_US.UTF-8',\n 'HOME=/home/jovyan',\n 'MINICONDA_VERSION=4.5.1'],\n 'Cmd': ['jupyter', 'notebook', '--ip=0.0.0.0', '--port=58938'],\n 'Image': 'jupyter/base-notebook',\n 'Volumes': None,\n 'WorkingDir': '/home/jovyan',\n 'Entrypoint': ['tini', '-g', '--'],\n 'OnBuild': None,\n 'Labels': {'maintainer': 'Jupyter Project <jupyter@googlegroups.com>'}},\n 'NetworkSettings': {'Bridge': '',\n 'SandboxID': '',\n 'HairpinMode': False,\n 'LinkLocalIPv6Address': '',\n 'LinkLocalIPv6PrefixLen': 0,\n 'Ports': {},\n 'SandboxKey': '',\n 'SecondaryIPAddresses': None,\n 'SecondaryIPv6Addresses': None,\n 'EndpointID': '',\n 'Gateway': '',\n 'GlobalIPv6Address': '',\n 'GlobalIPv6PrefixLen': 0,\n 'IPAddress': '',\n 'IPPrefixLen': 0,\n 'IPv6Gateway': '',\n 'MacAddress': '',\n 'Networks': {'bridge': {'IPAMConfig': None,\n 'Links': None,\n 'Aliases': None,\n 'NetworkID': '',\n 'EndpointID': '',\n 'Gateway': '',\n 'IPAddress': '',\n 'IPPrefixLen': 0,\n 'IPv6Gateway': '',\n 'GlobalIPv6Address': '',\n 'GlobalIPv6PrefixLen': 0,\n 'MacAddress': '',\n 'DriverOpts': None}}}}" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(container.logs().decode('utf8'))", | |
"execution_count": 47, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "[I 10:50:59.099 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret\n[I 10:50:59.262 NotebookApp] JupyterLab beta preview extension loaded from /opt/conda/lib/python3.6/site-packages/jupyterlab\n[I 10:50:59.262 NotebookApp] JupyterLab application directory is /opt/conda/share/jupyter/lab\n[I 10:50:59.265 NotebookApp] Serving notebooks from local directory: /home/jovyan\n[I 10:50:59.265 NotebookApp] 0 active kernels\n[I 10:50:59.265 NotebookApp] The Jupyter Notebook is running at:\n[I 10:50:59.265 NotebookApp] http://53b926531746:58938/?token=72f0ac9a4bf481fce1932b2f71b884fd85f5147845be0001\n[I 10:50:59.265 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).\n[C 10:50:59.266 NotebookApp] \n \n Copy/paste this URL into your browser when you connect for the first time,\n to login with a token:\n http://53b926531746:58938/?token=72f0ac9a4bf481fce1932b2f71b884fd85f5147845be0001&token=72f0ac9a4bf481fce1932b2f71b884fd85f5147845be0001\n[I 10:51:22.954 NotebookApp] 302 GET / (172.17.0.1) 0.55ms\n[I 10:51:22.958 NotebookApp] 302 GET /tree? (172.17.0.1) 0.61ms\n[I 10:52:36.154 NotebookApp] 302 GET / (172.17.0.1) 0.65ms\n[I 10:52:36.162 NotebookApp] 302 GET /tree (172.17.0.1) 0.77ms\n[W 10:52:41.519 NotebookApp] Forbidden\n[W 10:52:41.520 NotebookApp] 403 GET /api/status (172.17.0.1) 0.96ms referer=None\n\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import requests\n\nr = requests.get(\"http://localhost:%i/api\" % port)\nr.json()", | |
"execution_count": 53, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 53, | |
"data": { | |
"text/plain": "{'version': '5.5.0'}" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import requests\n\nr = requests.get(\"http://localhost:%i/api/contents/work?token=72f0ac9a4bf481fce1932b2f71b884fd85f5147845be0001\" % port)\nr.json()", | |
"execution_count": 52, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 52, | |
"data": { | |
"text/plain": "{'name': 'work',\n 'path': 'work',\n 'last_modified': '2018-06-15T10:56:36.905869Z',\n 'created': '2018-06-15T10:56:36.905869Z',\n 'content': [{'name': 'Untitled.ipynb',\n 'path': 'work/Untitled.ipynb',\n 'last_modified': '2018-06-15T10:56:36.905869Z',\n 'created': '2018-06-15T10:56:36.905869Z',\n 'content': None,\n 'format': None,\n 'mimetype': None,\n 'size': 72,\n 'writable': True,\n 'type': 'notebook'}],\n 'format': 'json',\n 'mimetype': None,\n 'size': None,\n 'writable': True,\n 'type': 'directory'}" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "After we are done, remove the container" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "container.remove(force=True)", | |
"execution_count": 55, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.6.5", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment