4 ms·
Why is running a db in a container with the data directory mounted from the host is such a bad idea? Dropping the container on a new host with a copy of the dat
by pmontra 10y ago
Why is running a db in a container with the data directory mounted from the host is such a bad idea? Dropping the container on a new host with a copy of the data directory looks easier than having to install the db from scratch, even with automatic tools. Are there performance penalties at run time?
- swap32 10y agoIt is fine for dev, but not for production. To quote from the link at the end of the article- "Docker is meant to be stateless. Containers have no permanent disk storage, whatever happens is ephemeral and is gone when the container stops. Containers are not meant to store data. Actually, they are meant by design to NOT store data. Any attempt to go against this philosophy is bound to disaster. Moreover. Docker is locking away processes and files through its abstraction, they are unreachable as if they didn’t exist. It prevents from doing any sort of recovery if something goes wrong" "A crash would destroy the database and affect all systems connecting to it. It is an erratic bug, triggered more frequently under intensive usage. A database is the ultimate IO intensive load, that’s a guaranteed kernel panic. Plus, there is another bug that can corrupt the docker mount (destroying all data) and possibly the system filesystem as well (if they’re on the same disk)."
- cpuguy83 10y agoAll these statements are patently false. 1. Containers are not ephemeral. They have a lifecycle. Data written in the container is persisted to disk and available after the container is stopped and then started again. 2. Processes/files/etc are not locked away as if they don't exist. See `ps aux` on the host. You will see all the processes running. You can inspect the filesystems for each container, etc. There is no magic here. 3. A database crash could cause data corruption inside a container or not. This has nothing to do with the container, and chances of a database crash are not made worse by being in a container. That said, I would let a volume driver manage persistent storage rather than manually managing this through the host fs... but that's my preference. --- EDIT --- Disclaimer: I work at Docker Inc, and am a maintainer on the Docker project.
- swap32 10y ago>> Data written in the container is persisted to disk Even if you don't mount any folder from the disk onto the container? Are you sure? Then everything I know about containers is just wrong.
- cpuguy83 10y agoYes. The filesystem in the container is a real filesystem backed by the disk. How this happens is dependent on the storage driver used. The `aufs` driver (default when available), as well as `overlay(2)` and `vfs` drivers just sit on top of the existing filesystem at `/var/lib/docker` (or the defined docker root). BTRFS, ZFS, and devicemapper must be pre-configured to even use and depends on how you configure these, but still generally would be on an actual disk.
- vel0city 10y agoI think there's a bit of mix up between what an image is and what a container is. You normally don't write data to an image, but you can write data to the container. You can keep this data so long as you keep the container, and you can commit that container's data to the image if you wish. I've found a good place to visualize how the filesystems work was this blog: http://merrigrove.blogspot.com/2015/10/visualizing-docker-containers-and-images.html http://merrigrove.blogspot.com/2015/10/visualizing-docker-co...
- eggie5 10y agoI keep hearing that you shouldn't containerize databases. What is the motivation behind this?
- swap32 10y agosee my comment above - https://news.ycombinator.com/item?id=12930829 https://news.ycombinator.com/item?id=12930829
- kossae 10y agoI still don't understand this theory. As stated above, containers have the option to mount volumes on the host file system. Anything written while the container running is immediately persisted, and if the container dies you just re-mount the volume and continue as normal. To harden this even further, you can run clustered DB nodes in Docker (+<your_preferred_orchestration_tool>) quite easily. So with persisted data, multiple node replication, and server snapshots I'd be interested to know as well.