diff --git a/runlike/inspector.py b/runlike/inspector.py index 80af8c4..8f0c703 100644 --- a/runlike/inspector.py +++ b/runlike/inspector.py @@ -117,6 +117,19 @@ def parse_ports(self): self.options.append(f"{option_part}{hostname_part}{host_port_part}{container_port}{protocol_part}") + def parse_volumes(self): + mounts = self.get_container_fact("Mounts") + for mount in mounts: + if mount["Type"] == "volume": + volume_format = f'{mount["Name"]}:{mount["Destination"]}' + else: + volume_format = f'{mount["Source"]}:{mount["Destination"]}' + if mount.get("RW"): + volume_format += ':rw' + else: + volume_format += ':ro' + self.options.append(f"--volume {volume_format}") + def parse_links(self): links = self.get_container_fact("HostConfig.Links") link_options = set() @@ -233,9 +246,9 @@ def format_cli(self): self.parse_pid() self.parse_cpuset() + self.parse_volumes() + self.multi_option("Config.Env", "env") - self.multi_option("HostConfig.Binds", "volume") - self.multi_option("Config.Volumes", "volume") self.multi_option("HostConfig.VolumesFrom", "volumes-from") self.multi_option("HostConfig.CapAdd", "cap-add") self.multi_option("HostConfig.CapDrop", "cap-drop") diff --git a/test_runlike.py b/test_runlike.py index 87fe371..8358b80 100644 --- a/test_runlike.py +++ b/test_runlike.py @@ -60,10 +60,10 @@ def test_udp_with_host_port_and_ip(self): def test_host_volumes(self): cur_dir = os.path.dirname(os.path.realpath(__file__)) - self.expect_substr("--volume=%s:/workdir" % pipes.quote(cur_dir)) + self.expect_substr("--volume %s:/workdir:rw" % pipes.quote(cur_dir)) def test_no_host_volume(self): - self.expect_substr('--volume=/random_volume') + self.expect_substr(':/random_volume:rw') def test_tty(self): self.expect_substr('-t \\') @@ -82,7 +82,8 @@ def test_restart_with_max(self): self.expect_substr('--restart=on-failure:3 \\', 3) def test_restart_not_present(self): - self.dont_expect_substr('--restart', 4) + # If the restart policy is not set, the default value is no. + self.expect_substr('--restart=no \\', 4) def test_hostname(self): self.expect_substr('--hostname=Essos \\') @@ -91,7 +92,8 @@ def test_hostname_not_present(self): self.dont_expect_substr('--hostname \\', 2) def test_network_mode(self): - self.dont_expect_substr('--network', 1) + # When no network mode is set, bridge is used by default + self.expect_substr('--network=bridge', 1) self.expect_substr('--network=host', 2) self.expect_substr('--network=runlike_fixture_bridge', 3)