docker
docker copied to clipboard
rootfs persistence
what directories need to be made a (docker) volume, in order to make the configuration persistent?
Here's ideas i explored:
- Mounting OverlayFS inside container, like OpenWrt does, is not a good idea because it requires escalating privileges for Docker.
- Committing container as new image is possible but requires scripting around start/stop process and only could happen on container shutdown.
- There is not much information about which folders in OpenWrt are crucial for backing up. So if you just persist
/etc
and/bin
, something will break sooner or later. - Let's persist everything then! I copied all files from image to host and tried to mount that as
/
. Docker does not allow this unfortunately. - This is due to runtime-created directories like
/run
and/proc
. My current workaround is that i mount everything copied from image as a separate volume. - Original OpenWrt container kinda loses its purpose after this, so i just use empty one with predefined CMD and ENV.
My Dockerfile and docker-compose:
FROM scratch
CMD /sbin/init
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
version: "3.9"
services:
openwrt:
container_name: openwrt
# image built from above Dockerfile
image: openwrt:empty
# my network setup... replace with yours
cap_add: [NET_ADMIN]
network_mode: none
# mounting every folder from original container
volumes:
- /mnt/stuff/docker/openwrt/bin:/bin
- /mnt/stuff/docker/openwrt/etc:/etc
- /mnt/stuff/docker/openwrt/lib:/lib
- /mnt/stuff/docker/openwrt/lib64:/lib64
- /mnt/stuff/docker/openwrt/mnt:/mnt
- /mnt/stuff/docker/openwrt/overlay:/overlay
- /mnt/stuff/docker/openwrt/rom:/rom
- /mnt/stuff/docker/openwrt/root:/root
- /mnt/stuff/docker/openwrt/sbin:/sbin
- /mnt/stuff/docker/openwrt/tmp:/tmp
- /mnt/stuff/docker/openwrt/usr:/usr
- /mnt/stuff/docker/openwrt/var:/var
- /mnt/stuff/docker/openwrt/www:/www