jett
jett

Reputation: 997

Docker container behavior when used in production

I am currently reading up on Docker. From what I understand, a container which is based on an image saves only the changes. If I were to use this in a production setup, does it persist it as soon as changes are written to disk by applications running "inside" the container or does it have to be done manually?

My concern is - what if the host abruptly shuts down? Will all the changes be lost?

Upvotes: 3

Views: 448

Answers (1)

mbarthelemy
mbarthelemy

Reputation: 12913

The theory is that there's no real difference between a Docker container and a classical VM or physical host in most situations.

If the host abruptly dies, you can loose recent data using a container as well as using a physical host:

  • your application may not have decided to really send the write operation to save the data on disk,

  • the Operating System may have decided to wait a bit before sending data to storage devices

  • the filesystem may not have finished the write

  • the data may not have been really flushed to the physical storage device.

Now by default, Docker uses AUFS (stackable filesystem) which works at the file level.

If you're writing to a file that was existing in the Docker image, AUFS will first copy this base file to the upper, writable layer (container), before writing your change. This causes a delay depending on the size of the original file. Interesting and more technical information here.

I guess that if a power cut occurs happens while this original file is being copied and before your changes have been written, then that would be one reason to get more data loss with a Docker container than with any "classical" host.

You can move your critical data to a Docker "volume", which would be a regular filesystem on the host, bind-mounted into the container. This is the recommended way to deal with important data that you want to keep across containers deployments

To mitigate the AUFS potential issue, you could tell Docker to use LVM thin provisioning block devices instead of AUFS (wipe /var/lib/dockerand start the daemon with docker -d -s devicemapper). However I don't know if this storage backend received as much testing as the default AUFS one (it works ok for me though).

Upvotes: 4

Related Questions