on master help sign in
Replace existing container on 'c init'
commit0060d9fbfbfca2c895edc1c974c7b835f061af55 authoriko <mail@iko.soy> dateSat 27 Jun 2026, 21:15 (3 months ago) parent8d81911
2 files changed+5−5
README.md+2−4 c+3−1
README.md+2−4
@@ -75,12 +75,10 @@ Working from a checkout, [`./c init`](./c) / `./c start` are equivalent — and
7575
7676## Re-running after a rebuild
7777
78−`container` keeps the loaded image and the created container, so remove them
79−before re-initialising:
78+Just run `init` again — it reloads the image and replaces the existing container
79+(removing the old one first), so there's nothing to clean up:
8080
8181```sh
82−container rm <dir> # the container is named after the directory
83−container image rm nix-container:latest
8482nix run github:ilyakooo0/nix-container -- init
8583```
8684
c+3−1
@@ -1,6 +1,6 @@
11#!/usr/bin/env fish
22# Manage a container named after the current directory.
3−# c init [-c FILE] [extra create args] build + load the image, then create it
3+# c init [-c FILE] [extra create args] build + load the image, then (re)create it
44# (packages from FILE, default ./container.nix)
55# c start start it and attach
66
@@ -45,6 +45,8 @@ switch $argv[1]
4545 rm -rf $tmp
4646 test $rc -eq 0; or exit $rc
4747
48+ # Replace any existing container of the same name.
49+ container rm --force $name 2>/dev/null
4850 container create --name $name --ssh -it $argv nix-container:latest
4951 case start
5052 container start -ai $name