# sed -i doesn't reach a container's single-file bind mount

my nginx ran in Docker with `nginx.conf` bind-mounted into it. while adding the Nujoom server block, my notes from that day say: "`sed -i` swaps file inodes — Docker bind mounts lose the file."

`sed -i` doesn't edit the file. it writes a new one and renames it over the old name, so the name now points at a new inode. a bind mount of a single file is attached to the inode, not the name. the container keeps the old, now-deleted file.

easy to see:

```bash
$ echo "worker_processes 1;" > conf.txt
$ docker run -d --name bindtest -v $PWD/conf.txt:/conf.txt:ro alpine sleep 300
$ ls -i conf.txt
816198 conf.txt
$ sed -i 's/1/2/' conf.txt
$ ls -i conf.txt
816816 conf.txt
$ docker exec bindtest cat /conf.txt
worker_processes 1;
```

the catch that makes it confusing: once `sed -i` has run, writing the file in place doesn't help either. `cat >` or `>` keep the inode, but it's the new inode, and the container is still holding the first one:

```bash
$ echo "worker_processes 3;" > conf.txt
$ docker exec bindtest cat /conf.txt
worker_processes 1;
```

## fix

recreate the container so the mount picks up the current file:

```bash
docker compose up -d --force-recreate nginx
```

after that, edit with something that writes in place, like `cat > file`. an edit written that way shows up inside straight away. or mount the directory instead of the file: a directory mount looks names up live, so even `sed -i` shows through.

---

see also: [nothing crashed](/articles/nothing-crashed)
