2

Docker images are read only. When we instantiate a container from an image, the processes hosted in the container are able to write on disk, but those changes do not survive container restart. There are plenty of docker containers hosting databases services like Sql Server: https://hub.docker.com/r/microsoft/mssql-server-windows/

Doesn't the read only nature of Docker images defeat the purpose of durable databases? What do I see wrong?

Btw, I see great usability of this read-only nature in automated tests (no need to roll back), but that is not the primary use of a db.

user256890
  • 3,396
  • 5
  • 28
  • 45
  • Docker images are not read only. They could be changed with ```docker build``` or ```docker commit```. Docker container could store data, the data could survive if you don't remove its container. – Tuan Nov 23 '16 at 09:10
  • 1
    Thank you Tuan. Please, correct me if I am wrong, but 'docker build' and 'docker commit' are "design time" changes, while db commits are "runtime" changes. Obviously, I am interested in the latter. – user256890 Nov 23 '16 at 09:17

2 Answers2

3

If you want durable data that survives a restart of your container, you can use a volume for storing the data.

The MySQL image uses the /var/lib/mysql directory to store the "live" data of the database. If you map this folder to a Docker volume, it will survive restarts and deleting the container - unless you also delete the volume. It's possible that the MS SQL image has a similar directory that can be mapped to a volume to make the data durable.

You're right that the default behavior is to not be durable (great for throwaway tests), but if you want to have it survive, you can use volumes.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
1

There are two methods for supporting SQL Server databases in containers. Using ADDDB will copy the DB into the container private file system, and this database can persist as long as the container is not deleted. The database will be stopped when the container is stopped, and reattached when the container is started. It will, however, be lost when the container is deleted. The alternative is to use MOUNTDB, which mounts the database to the container either with a local host or remote. In this case the file persists if the container is deleted.

paul stanton
  • 936
  • 7
  • 7