Skip to content

Commit 226c9d6

Browse files
committed
docker compat: use hyphens to join container names
docker-compose uses - not _ to join container names to project. not a huge thing, but for services making assumptions based on this it can catch off guard, and is easy to make the same. Signed-off-by: Matt Phillips <[email protected]>
1 parent 626e278 commit 226c9d6

10 files changed

+26
-26
lines changed

podman_compose.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ def _parse_compose_file(self):
19791979

19801980
container_names_by_service[service_name] = []
19811981
for num in range(1, replicas + 1):
1982-
name0 = f"{project_name}_{service_name}_{num}"
1982+
name0 = f"{project_name}-{service_name}-{num}"
19831983
if num == 1:
19841984
name = service_desc.get("container_name", name0)
19851985
else:

tests/integration/test_podman_compose_deps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_deps(self):
2626
"wget -O - http://web:8000/hosts",
2727
])
2828
self.assertIn(b"HTTP request sent, awaiting response... 200 OK", output)
29-
self.assertIn(b"deps_web_1", output)
29+
self.assertIn(b"deps-web-1", output)
3030
finally:
3131
self.run_subprocess_assert_returncode([
3232
podman_compose_path(),

tests/integration/test_podman_compose_extends_w_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def test_extends_w_file(self): # when file is Dockerfile for building the image
2929
compose_yaml_path(),
3030
"ps",
3131
])
32-
self.assertIn("extends_w_file_web_1", str(output))
33-
self.assertIn("extends_w_file_important_web_1", str(output))
32+
self.assertIn("extends_w_file-web-1", str(output))
33+
self.assertIn("extends_w_file-important_web-1", str(output))
3434
finally:
3535
self.run_subprocess_assert_returncode([
3636
podman_compose_path(),

tests/integration/test_podman_compose_extends_w_file_subdir.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_extends_w_file_subdir(self): # when file is Dockerfile for building th
2929
compose_yaml_path(),
3030
"ps",
3131
])
32-
self.assertIn("extends_w_file_subdir_web_1", str(output))
32+
self.assertIn("extends_w_file_subdir-web-1", str(output))
3333
finally:
3434
self.run_subprocess_assert_returncode([
3535
podman_compose_path(),

tests/integration/test_podman_compose_ipam_default.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-License-Identifier: GPL-2.0
1+
# SPDt-License-Identifier: GPL-2.0
22

33
import json
44
import os
@@ -34,7 +34,7 @@ def test_ipam_default(self):
3434
[
3535
"podman",
3636
"inspect",
37-
"ipam_default_testipam_1",
37+
"ipam_default-testipam-1",
3838
],
3939
)
4040
network_info = json.loads(output.decode('utf-8'))[0]

tests/integration/test_podman_compose_multicompose.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def test_multicompose(self):
3838
os.path.join(os.path.join(test_path(), "multicompose"), "d2/docker-compose.yml"),
3939
"ps",
4040
])
41-
self.assertIn(b"d1_web1_1", output)
42-
self.assertIn(b"d1_web2_1", output)
41+
self.assertIn(b"d1-web1-1", output)
42+
self.assertIn(b"d1-web2-1", output)
4343

4444
output, _ = self.run_subprocess_assert_returncode([
4545
"podman",
4646
"exec",
4747
"-ti",
48-
"d1_web1_1",
48+
"d1-web1-1",
4949
"sh",
5050
"-c",
5151
"set",
@@ -58,7 +58,7 @@ def test_multicompose(self):
5858
"podman",
5959
"exec",
6060
"-ti",
61-
"d1_web2_1",
61+
"d1-web2-1",
6262
"sh",
6363
"-c",
6464
"set",
@@ -70,7 +70,7 @@ def test_multicompose(self):
7070
"podman",
7171
"exec",
7272
"-ti",
73-
"d1_web1_1",
73+
"d1-web1-1",
7474
"sh",
7575
"-c",
7676
"cat /var/www/html/index.txt",
@@ -82,7 +82,7 @@ def test_multicompose(self):
8282
"podman",
8383
"exec",
8484
"-ti",
85-
"d1_web2_1",
85+
"d1-web2-1",
8686
"sh",
8787
"-c",
8888
"cat /var/www/html/index.txt",

tests/integration/test_podman_compose_nets_test1.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def test_nets_test1(self):
3434
compose_yaml_path(),
3535
"ps",
3636
])
37-
self.assertIn(b"nets_test1_web1_1", output)
38-
self.assertIn(b"nets_test1_web2_1", output)
37+
self.assertIn(b"nets_test1-web1-1", output)
38+
self.assertIn(b"nets_test1-web2-1", output)
3939

4040
response = requests.get('http://localhost:8001/index.txt')
4141
self.assertTrue(response.ok)
@@ -49,7 +49,7 @@ def test_nets_test1(self):
4949
output, _ = self.run_subprocess_assert_returncode([
5050
"podman",
5151
"inspect",
52-
"nets_test1_web1_1",
52+
"nets_test1-web1-1",
5353
])
5454
container_info = json.loads(output.decode('utf-8'))[0]
5555

tests/integration/test_podman_compose_nets_test2.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def test_nets_test2(self):
3434
compose_yaml_path(),
3535
"ps",
3636
])
37-
self.assertIn(b"nets_test2_web1_1", output)
38-
self.assertIn(b"nets_test2_web2_1", output)
37+
self.assertIn(b"nets_test2-web1-1", output)
38+
self.assertIn(b"nets_test2-web2-1", output)
3939

4040
response = requests.get('http://localhost:8001/index.txt')
4141
self.assertTrue(response.ok)
@@ -49,13 +49,13 @@ def test_nets_test2(self):
4949
output, _ = self.run_subprocess_assert_returncode([
5050
"podman",
5151
"inspect",
52-
"nets_test2_web1_1",
52+
"nets_test2-web1-1",
5353
])
5454
container_info = json.loads(output.decode('utf-8'))[0]
5555

5656
# check if network got specific name from networks top-level element
5757
self.assertEqual(
58-
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2_mystack"
58+
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2-mystack"
5959
)
6060

6161
# check if Host port is the same as prodvided by the service port
@@ -70,12 +70,12 @@ def test_nets_test2(self):
7070
output, _ = self.run_subprocess_assert_returncode([
7171
"podman",
7272
"inspect",
73-
"nets_test2_web2_1",
73+
"nets_test2-web2-1",
7474
])
7575
container_info = json.loads(output.decode('utf-8'))[0]
7676

7777
self.assertEqual(
78-
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2_mystack"
78+
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2-mystack"
7979
)
8080

8181
self.assertEqual(

tests/integration/test_podman_compose_networks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def test_networks(self):
6363
'"{{.Names}}"',
6464
]
6565
out, _ = self.run_subprocess_assert_returncode(check_cmd)
66-
self.assertIn(b"nets_test_ip_web1_1", out)
67-
self.assertIn(b"nets_test_ip_web2_1", out)
66+
self.assertIn(b"nets_test_ip-web1-1", out)
67+
self.assertIn(b"nets_test_ip-web2-1", out)
6868

6969
expected_wget = {
7070
"172.19.1.10": "test1",

tests/integration/test_podman_compose_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_down_with_network(self):
200200
"-d",
201201
])
202202
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
203-
self.assertIn("network_mystack", output.decode())
203+
self.assertIn("network-mystack", output.decode())
204204
finally:
205205
self.run_subprocess_assert_returncode([
206206
"coverage",
@@ -211,4 +211,4 @@ def test_down_with_network(self):
211211
"down",
212212
])
213213
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
214-
self.assertNotIn("network_mystack", output.decode())
214+
self.assertNotIn("network-mystack", output.decode())

0 commit comments

Comments
 (0)