Use docker as VM with persistent storage

i’m using docker for some app and works great.

now i’m need to create a container (understood as a VM) so with persistent storage of all container.
such as a VM or container LXD…

i have 2 choices,
1 install DOCKER and LXD on same host (rocky linux host)
use docker for some things and LXD for this specific
2 creare a docker compose container with image: almalinux:latest
but when i write some files or app they should persist to reboot
entire root /

can i create a docker as container/VM and persist all root storage?

thank you

You can persist changes with bind mounts and/or Docker volumes, but that’s usually just for data folders.

Alternatively, you can commit the changes made to a running container to create a new image.


But containers are not VMs.

i’m reading about commit but in my case i have commit every day…

so other way is LXD+docker.
is there about issues or is not recommended use lcx+docker on same host?

thank you

Really, really bad idea. I hope you meant you commit the version controlled source code and not the container. If you really need it once, you can commit a container, although that is not recommended either. But committing every day would result so many layers, eventually you couldn’t commit more.

LXD and Docker could run on the same host, but you could have network issues as Docker writes firewall rules and that is not really compatible with LXD. I know it from experience, because on a server I had to configure LXD, someone else installed Docker and suddenly my virtual machines didn’t have access to the internet and internal traffic didn’t work either so I had to add additional firewall rules and start a proxy on the host to forward traffic to the vitual machines…

So if you need LXD, use that for running containers and virtual machines. If you need Docker too, run a virtual machine with LXD and run Docker containers in that virtual machine. You could run Docker in an LXC container too, but that is not trivial and requires additional parameters and privileges.

What is a container “understood as a VM”? Its either virtual machine or a container.

Regarding persistent storage, @bluepuma77 gave you the answer so searching for bind mounts in the documentation or simply on Google can give you everything you need. .