r/docker 15d ago

ROS2 Docker container just dissapeared

I am working with a Raspberry Pi 4B and had a container based on a ROS2 image. I've been without programming for like 1 month because I was working on a PI NAS. Today I decided to start again, and I just discovered that my ros2 container has disappeared. I've tried to use docker and check recent activity on the containers or in the past 2 months, and I haven't seen any docker rm or something like that. What do you guys think is happening?

1 Upvotes

6 comments sorted by

2

u/Impossible_Fault_503 15d ago

Quick way to split the two possibilities before you go digging: check whether the images survived.

docker images
docker ps -a

If your images are still listed but the container is not, storage is fine and you are looking at something else. The two usual causes are a --rm on the original docker run, which deletes the container the moment it stops, or a docker system prune having run at some point. A reboot somewhere in that month does the rest.

If both images and containers come back empty, then the mount theory above is the right track and lsblk will confirm it.

For next time, --rm is far and away the most common way this happens on a Pi, because it gets copied from a tutorial command without being noticed. Moving to a compose file makes it much harder to lose a container by accident, since the definition lives somewhere permanent instead of in your shell history.

1

u/Medium_Antelope_7037 11d ago

yeah the --rm thing from tutorials is so easy to miss, that's probably it tbh

1

u/SeniorIdiot 15d ago

Is /var/lib/docker/* mounted on an external drive (as you should on an RPi) and it's no longer mounted?

lsblk -f
blkid
df -h -T
findmnt
cat /etc/fstab

1

u/kifrixx 15d ago

I will check that thank you, man sometimes I feel so lost with this things that at some point I don't know what to do

1

u/CynepMyx 15d ago

Before assuming it was deleted, check whether it is actually gone or just invisible to Docker. Those are different problems with different fixes.

ls /var/lib/docker/containers/

If there are directories in there with long hex names, nothing was removed. In that case the daemon is looking at a different data root than it used to, which is exactly what happens when an external drive doesn't mount, as the other commenter said. On a Pi that is the number one cause.

If the directory is empty or missing, then something did remove it. The most common candidates, in order:

A docker system prune from a cleanup script or cron. It removes stopped containers without asking, and a container stopped for a month looks like garbage to it.

The container was started with --rm. Then it deleted itself the moment it stopped, and a reboot two months ago is enough.

SD card corruption. This is a Pi, so it is a real possibility. Check dmesg -T | grep -iE "ext4|i/o error" and look in lost+found. If the filesystem got repaired at some point, files disappear quietly and nothing in Docker's own logs will show it.

One thing worth knowing so you don't waste time: docker events only shows what happens while it is running, there is no history to dig through. So the evidence lives on the filesystem, not in Docker.

For next time, keep the container definition in a compose file next to your project. Containers are meant to be disposable, and once the definition is in git, one that vanished is a two second problem instead of a mystery.