summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/cloud/docker/docker_container.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/modules/cloud/docker/docker_container.py')
-rw-r--r--lib/ansible/modules/cloud/docker/docker_container.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py
index 2c8c7df85d..53eb5131a1 100644
--- a/lib/ansible/modules/cloud/docker/docker_container.py
+++ b/lib/ansible/modules/cloud/docker/docker_container.py
@@ -644,6 +644,9 @@ options:
container port, 9000 is a host port, and 0.0.0.0 is a host interface."
- Port ranges can be used for source and destination ports. If two ranges with
different lengths are specified, the shorter range will be used.
+ Since Ansible 2.10, if the source port range has length 1, the port will not be assigned
+ to the first port of the destination range, but to a free port in that range. This is the
+ same behavior as for C(docker) command line utility.
- "Bind addresses must be either IPv4 or IPv6 addresses. Hostnames are *not* allowed. This
is different from the C(docker) command line utility. Use the L(dig lookup,../lookup/dig.html)
to resolve hostnames."
@@ -886,8 +889,16 @@ EXAMPLES = '''
devices:
- "/dev/sda:/dev/xvda:rwm"
ports:
+ # Publish container port 9000 as host port 8080
- "8080:9000"
+ # Publish container UDP port 9001 as host port 8081 on interface 127.0.0.1
- "127.0.0.1:8081:9001/udp"
+ # Publish container port 9002 as a random host port
+ - "9002"
+ # Publish container port 9003 as a random host port in range 8000-8100
+ - "9003:8000-8100"
+ # Publish container ports 9010-9020 to host ports 7000-7010
+ - "9010-9020:7000-7010"
env:
SECRET_KEY: "ssssh"
# Values which might be parsed as numbers, booleans or other types by the YAML parser need to be quoted
@@ -1656,7 +1667,10 @@ class TaskParameters(DockerBaseClass):
if p_len == 1:
port_binds = len(container_ports) * [(default_ip,)]
elif p_len == 2:
- port_binds = [(default_ip, port) for port in parse_port_range(parts[0], self.client)]
+ if len(container_ports) == 1:
+ port_binds = [(default_ip, parts[0])]
+ else:
+ port_binds = [(default_ip, port) for port in parse_port_range(parts[0], self.client)]
elif p_len == 3:
# We only allow IPv4 and IPv6 addresses for the bind address
ipaddr = parts[0]
@@ -1666,7 +1680,10 @@ class TaskParameters(DockerBaseClass):
if re.match(r'^\[[0-9a-fA-F:]+\]$', ipaddr):
ipaddr = ipaddr[1:-1]
if parts[1]:
- port_binds = [(ipaddr, port) for port in parse_port_range(parts[1], self.client)]
+ if len(container_ports) == 1:
+ port_binds = [(ipaddr, parts[1])]
+ else:
+ port_binds = [(ipaddr, port) for port in parse_port_range(parts[1], self.client)]
else:
port_binds = len(container_ports) * [(ipaddr,)]