0

I have a docker SQL Server image that I configure and then share with team. Each time I update the data the image size increases significantly.

I start with the mcr.microsoft.com/mssql/server:2019-latest image which is about 1.6 gigs. I have to do a custom setup, such as adding a MasterKey, a LinkedServer, and some logins. Then I restore backups of my databases and commit the container to create a new image. This image is about 6.5G. That's understandable because I have added my data. I push this image to the registry for the rest of our team to use.

Later, I refresh the data to keep the image updated. To do this, I drop the databases, restore from new backups, and commit the container. The size of my data only slightly increased, but the size of my image is now 13G (about double the last image).

Today I noticed a problem with a linked server definition. I fixed it, and committed the container. There was no data changed but now the image is over 20G.

Because of the custom configuration at the beginning, I don't want to start over with the default image each time. Also, I may only restore one database and leave others the same.

What is causing this?

Does each commit include the previous image as a layer, which is essentially doubling the size of the image?

Any tips of how to make this image smaller.

Don Chambers
  • 3,798
  • 9
  • 33
  • 74
  • Is "doclekr" a typo by chance? – Dale K Sep 09 '22 at 01:29
  • In fact, for the reasons you describe, committing an image _always_ results in a larger image. In your case it sounds like if you touch the database data at all, the new image will be ~6 GB larger. `docker commit` is almost never a best practice and I wouldn't use it here. Could you distribute the database data separately from the database code, or `COPY` the data in a Dockerfile? – David Maze Sep 09 '22 at 01:48
  • _Does each commit include the previous image as a layer, which is essentially doubling the size of the image?_ Yes. Docker images use a layered filesystem. Every filesystem-related command like `COPY`, `RUN`, etc., adds another layer to the image thus increasing its size. It doesn't modify previous layers so deleting files in an isolated `RUN` command, for example, will not reduce the overall image size. – AlwaysLearning Sep 09 '22 at 03:08
  • Tips: Rebuild images from scratch, starting with the smallest possible image; consolidate `RUN` commands to reduce layer counts; Follow `apt-update`, `apt-get install`, etc., with `apt-get clean`. – AlwaysLearning Sep 09 '22 at 03:14

0 Answers0