nerdctl icon indicating copy to clipboard operation
nerdctl copied to clipboard

nerdctl compose removes containers on termination (stop vs down)

Open filex opened this issue 3 years ago • 6 comments

I use nerdctl in a lima vm on mac as a replacement for docker-compose.

docker compose (or docker-compose) supports a stop command. It retains the created containers by just stopping them. In oppose to that, the down command removes the containers after stopping. nerdctl only has the down command.

When I run nerdctl up and ctrl-c the process, this is effectively a down and the containers are removed.

One can reproduce this with a simple docker-compose.yml file:

version: '3'
services:
  test:
    image: nginx
    ports:
      - 1234:80
$ lima nerdctl compose up
INFO[0000] Ensuring image nginx                         
INFO[0000] Creating container docker-compose_test_1     
…

# ctrl+c
INFO[0295] Stopping containers (forcibly)               
INFO[0295] Stopping container docker-compose_test_1     

$ lima nerdctl ps -a
CONTAINER ID    IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES
# [no containers]

With the original docker-compose the stopped containers are still present:

$ docker-compose up
Creating network "docker-compose_default" with the default driver
Creating docker-compose_test_1 ... done
…

# ctrl+c
Gracefully stopping... (press Ctrl+C again to force)
Stopping docker-compose_test_1 ... done

$ docker ps -a
CONTAINER ID   IMAGE                         COMMAND                  CREATED          STATUS                      PORTS     NAMES
013c0570007f   nginx                         "/docker-entrypoint.…"   29 seconds ago   Exited (0) 12 seconds ago             docker-compose_test_1

Proposal:

  • add nerdctl compose stop command (and probably start?)
  • let the ctrl-c signal listener in nerdctl compose up trigger the stop command instead of down.

filex avatar Jan 05 '22 08:01 filex

$ nerdctl version
Client:
 Version:	v0.15.0
 Git commit:	b72b5ca14550b2e23a42787664b6182524c5053f

Server:
 containerd:
  Version:	v1.5.8
  GitCommit:	1e5ef943eb76627a6d3b6de8cd1ef6537f393a71

filex avatar Jan 05 '22 08:01 filex

I definitely second that. Fair to mention though that nerdctl stop can be used for now as a workaround until nerdctl compose stop has been implemented. Just if that was not already clear.

kgalli avatar Jan 12 '22 15:01 kgalli

I think this proposal is making sense.

I will make a try to impl it.

cc @AkihiroSuda would you mind assigning this issue to me?

Zheaoli avatar Mar 25 '22 05:03 Zheaoli

Any news about this 'stop' command implementation ? :) Best will be also to just start the stop containers defined in the compose file to not loose volumes associated. Thank you !

Hellboy94520 avatar Jul 16 '22 09:07 Hellboy94520

Any news about this 'stop' command implementation ? :)

Best will be also to just start the stop containers defined in the compose file to not loose volumes associated.

Thank you !

Working on it now,maybe this feature can be released in v0.23.0

Zheaoli avatar Jul 16 '22 19:07 Zheaoli

+1

Maintaining volumes is a really important feature; thank you for the great work!

egelja avatar Aug 08 '22 03:08 egelja

@Zheaoli are you still working on this? Otherwise I'd like to give it a try.

djdongjin avatar Nov 08 '22 16:11 djdongjin

@djdongjin Sure you can make a try

Zheaoli avatar Nov 09 '22 15:11 Zheaoli