Skip to content

Commit 1b673e8

Browse files
author
ds
committed
check if container already created
1 parent e789d98 commit 1b673e8

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

podman_compose.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,24 +3107,57 @@ async def compose_up(compose: PodmanCompose, args: argparse.Namespace) -> int |
31073107
.decode("utf-8")
31083108
.splitlines()
31093109
)
3110+
created_containers = []
31103111
diff_hashes = [i for i in hashes if i and i != compose.yaml_hash]
3111-
if (args.force_recreate and len(hashes) > 0) or len(diff_hashes):
3112+
if args.force_recreate and (hashes or diff_hashes):
31123113
log.info("recreating: ...")
31133114
down_args = argparse.Namespace(**dict(args.__dict__, volumes=False, rmi=None))
31143115
await compose.commands["down"](compose, down_args)
31153116
log.info("recreating: done\n\n")
3116-
# args.no_recreate disables check for changes (which is not implemented)
3117+
else:
3118+
# args.no_recreate disables check for changes (which is not implemented)
3119+
# so let's just check for running containers
3120+
created_containers = (
3121+
(
3122+
await compose.podman.output(
3123+
[],
3124+
"ps",
3125+
[
3126+
"--filter",
3127+
f"label=io.podman.compose.project={compose.project_name}",
3128+
"--filter",
3129+
"status=created",
3130+
"--filter",
3131+
"status=running",
3132+
"-a",
3133+
"--format",
3134+
"{{ .Names }}",
3135+
],
3136+
)
3137+
)
3138+
.decode("utf-8")
3139+
.splitlines()
3140+
)
3141+
log.debug("** Existing containers: %s", created_containers)
31173142

31183143
await create_pods(compose)
31193144
exit_code = 0
3145+
31203146
for cnt in compose.containers:
31213147
if cnt["_service"] in excluded:
31223148
log.debug("** skipping: %s", cnt["name"])
31233149
continue
3124-
podman_args = await container_to_args(compose, cnt, detached=False, no_deps=args.no_deps)
3125-
subproc_exit_code = await compose.podman.run([], "create", podman_args)
3126-
if subproc_exit_code is not None and subproc_exit_code != 0:
3127-
exit_code = subproc_exit_code
3150+
3151+
if args.force_recreate or cnt["name"] not in created_containers:
3152+
podman_args = await container_to_args(
3153+
compose, cnt, detached=False, no_deps=args.no_deps
3154+
)
3155+
subproc_exit_code = await compose.podman.run([], "create", podman_args)
3156+
3157+
if subproc_exit_code is not None and subproc_exit_code != 0:
3158+
exit_code = subproc_exit_code
3159+
else:
3160+
subproc_exit_code = 0
31283161

31293162
if not args.no_start and args.detach and subproc_exit_code is not None:
31303163
container_exit_code = await run_container(

0 commit comments

Comments
 (0)