示例#1
0
def test_get_port_mappings():
    image_name = "registry.fedoraproject.org/fedora"
    image_tag = "27"
    image = DockerImage(image_name, image_tag)

    command = DockerRunBuilder(additional_opts=["-p", "321:123"])

    try:
        image.get_metadata()
    except Exception:
        image.pull()

    container = image.run_via_binary(command)
    try:
        mappings = container.get_port_mappings(123)

        assert len(mappings) == 1
        assert mappings == [{"HostIp": '0.0.0.0', "HostPort": '321'}]

        mappings = container.get_port_mappings()
        assert len(mappings) == 1
        assert mappings == {
            '123/tcp': [{
                'HostIp': '0.0.0.0',
                'HostPort': '321'
            }]
        }
    finally:
        container.stop()
        container.delete()

    command = DockerRunBuilder()
    container = image.run_via_binary(command)
    try:
        mappings = container.get_port_mappings(123)

        assert not mappings
    finally:
        container.stop()
        container.delete()
示例#2
0
from conu import DockerImage, DockerContainer, DockerRunBuilder

image = DockerImage('centos/httpd-24-centos7')
image.pull()
command = DockerRunBuilder(additional_opts=["-p", "8080:8080"])
container = image.run_via_binary(command)
container.wait_for_port(port=8080, timeout=-1)

container.stop()
container.delete()