Skip to content

fix(installer): clean up Docker containers left by k3s on uninstall#46

Merged
MioYuuIH merged 2 commits intodevelopfrom
fix/uninstall-docker-containers-cleanup
Mar 16, 2026
Merged

fix(installer): clean up Docker containers left by k3s on uninstall#46
MioYuuIH merged 2 commits intodevelopfrom
fix/uninstall-docker-containers-cleanup

Conversation

@MioYuuIH
Copy link
Contributor

Problem

When k3s is installed with --docker, all Pod containers are managed by Docker and appear in docker ps with a k8s_ prefix. The k3s uninstall script (k3s-uninstall.sh) only handles its embedded containerd runtime and makes no Docker API calls, so these containers are silently left behind after uninstall.

This is a known upstream issue: k3s-io/k3s#1469.

Closes #45

Changes

Add remove_k3s_docker_containers() to the remove_k3s flow. After k3s-uninstall.sh runs, it:

  • Detects leftover containers using --filter "label=io.kubernetes.pod.name" (the label kubelet stamps on every container it creates via dockershim/cri-dockerd), which is more precise than matching the k8s_ name prefix
  • Lists the containers and prompts for confirmation before removing
  • In non-interactive environments (stdin is not a TTY): skips automatically and prints the manual cleanup command
  • With --yes / AUPLC_YES=1: removes without prompting, for scripted/CI use

Testing

  • Run ./auplc-installer uninstall with containers present, confirm prompt lists containers correctly
  • Answer N, confirm containers are not removed
  • Answer Y, confirm containers are stopped and removed
  • Run via pipe (echo y | ./auplc-installer uninstall), confirm non-interactive path triggers
  • Run with --yes, confirm auto-removal without prompt

k3s-uninstall.sh only handles its embedded containerd runtime. When k3s
is configured with --docker, Pod containers appear in `docker ps` with
a k8s_ prefix and are silently skipped by the uninstall script.

Add remove_k3s_docker_containers() to stop and remove all k8s_* Docker
containers after k3s-uninstall.sh runs. The function lists affected
containers and prompts for confirmation before removing. Behaviour in
non-interactive environments (CI/CD, pipes):
- stdin is not a TTY: skip automatically, print manual cleanup command
- --yes / -y flag or AUPLC_YES=1: remove without prompting

Upstream issue: k3s-io/k3s#1469
…ntainers

Replacing the 'name=k8s_' substring filter with a label-based filter on
'io.kubernetes.pod.name', which kubelet stamps on every container it
creates via dockershim/cri-dockerd. This prevents accidentally matching
user-created containers that happen to have 'k8s_' in their name.
@MioYuuIH MioYuuIH requested a review from KerwinTsaiii as a code owner March 16, 2026 04:04
@MioYuuIH MioYuuIH merged commit 86ab18d into develop Mar 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants