nerdctl icon indicating copy to clipboard operation
nerdctl copied to clipboard

`compose down --remove-orphans`

Open dbanty opened this issue 3 years ago • 5 comments

What is the problem you're trying to solve

Similar to #342, I would like to have the --remove-orphans option for compose down.

Describe the solution you'd like

Add the --remove-orphans flag to compose down.

Additional context

No response

dbanty avatar Aug 29 '22 17:08 dbanty

I'd like to help.

stillfox-lee avatar Aug 30 '22 09:08 stillfox-lee

plz go ahead @stillfox-lee

fahedouch avatar Aug 30 '22 14:08 fahedouch

Hi @dbanty , I find a compatibility issue with docker and containerd in orphan container use case. When we execute docker compose down it will return failed. Docker found an orphan container still in active, and it won't remove the related network. But containerd just remove network and leave the orphan container alone.

cat full.yaml
version: '3.1'

services:
  service1:
    image: alpine:3.13
    command: "sleep infinity"
  orphan:
    image: alpine:3.13
    command: "sleep infinity"

---

cat orphan.yaml
version: '3.1'

services:
  orphan:
    image: alpine:3.13
    command: "sleep infinity"

docker:

docker compose -f full.yaml up -d
[+] Running 3/3
 ⠿ Network compose-orphans_default       Created                                                                                                                                          0.1s
 ⠿ Container compose-orphans-orphan-1    Started                                                                                                                                          0.6s
 ⠿ Container compose-orphans-service1-1  Started

---
docker compose -f orphan.yaml down -v
[+] Running 1/1
 ⠿ Container compose-orphans-orphan-1  Removed                                                                                                                                           10.3s
 ⠿ Network compose-orphans_default     Error                                                                                                                                              0.0s
failed to remove network compose-orphans_default: Error response from daemon: error while removing network: network compose-orphans_default id 497799fb7117a56780a82e4bbfbfbfe984d5fcf41cf9af32af28d5c3e1cd33b1 has active endpoints

containerd:

nerdctl compose -f full.yaml up -d
INFO[0000] Creating network compose-orphans_default
INFO[0000] Ensuring image alpine:3.13
INFO[0000] Ensuring image alpine:3.13
INFO[0000] Creating container compose-orphans_service1_1
INFO[0000] Creating container compose-orphans_orphan_1

--- 
nerdctl compose -f orphan.yaml down -v
INFO[0000] Removing container compose-orphans_orphan_1
INFO[0000] Removing network compose-orphans_default

And the deviation also cause CI fail.

stillfox-lee avatar Sep 09 '22 04:09 stillfox-lee

Docker's behavior is correct, and eventually we have to fix the behavior of nerdctl, but that can be worked out later.

Could you find a test case that works with Docker, and confirm that it works with nerdctl too? Thanks

AkihiroSuda avatar Oct 11 '22 15:10 AkihiroSuda

Could you find a test case that works with Docker, and confirm that it works with nerdctl too? Thanks

Sure.

stillfox-lee avatar Oct 12 '22 02:10 stillfox-lee