Merge pull request #2629 from dbonev/2611-support-port-range-in-compose

Port range in exposed ports
This commit is contained in:
Joffrey F 2016-01-13 13:09:22 -08:00
commit c260eb910b
3 changed files with 34 additions and 1 deletions

View File

@ -38,7 +38,7 @@ DOCKER_CONFIG_HINTS = {
VALID_NAME_CHARS = '[a-zA-Z0-9\._\-]'
VALID_EXPOSE_FORMAT = r'^\d+(\/[a-zA-Z]+)?$'
VALID_EXPOSE_FORMAT = r'^\d+(\-\d+)?(\/[a-zA-Z]+)?$'
@FormatChecker.cls_checks(format="ports", raises=ValidationError)

View File

@ -646,6 +646,28 @@ class CLITestCase(DockerClientTestCase):
self.assertEqual(port_short, "127.0.0.1:30000")
self.assertEqual(port_full, "127.0.0.1:30001")
def test_run_with_expose_ports(self):
# create one off container
self.base_dir = 'tests/fixtures/expose-composefile'
self.dispatch(['run', '-d', '--service-ports', 'simple'])
container = self.project.get_service('simple').containers(one_off=True)[0]
ports = container.ports
self.assertEqual(len(ports), 9)
# exposed ports are not mapped to host ports
assert ports['3000/tcp'] is None
assert ports['3001/tcp'] is None
assert ports['3001/udp'] is None
assert ports['3002/tcp'] is None
assert ports['3003/tcp'] is None
assert ports['3004/tcp'] is None
assert ports['3005/tcp'] is None
assert ports['3006/udp'] is None
assert ports['3007/udp'] is None
# close all one off containers we just created
container.stop()
def test_run_with_custom_name(self):
self.base_dir = 'tests/fixtures/environment-composefile'
name = 'the-container-name'

View File

@ -0,0 +1,11 @@
simple:
image: busybox:latest
command: top
expose:
- '3000'
- '3001/tcp'
- '3001/udp'
- '3002-3003'
- '3004-3005/tcp'
- '3006-3007/udp'