SQLGeordie's Blog

Helping the SQL Server community……where i can!

Merge image layers in Docker using –squash — June 20, 2018

Merge image layers in Docker using –squash

A question which always gets asked regarding the union layered file system for images is whether the intermediary image layers can be merged into one? The answer is yes, you can –squash image layers during a build from a Dockerfile.

The attached video shows 2 example builds of the same Dockerfile, one is standard, the second using –squash to merge the layers.

Merge image layers in Docker

Example run script:

docker build -t NewImageNameHere . --squash

To view the image layers related to the newly created image you can run:

docker history NewImageNameHere

This will show all the layers created from each instruction in the dockerfile but the Imageid is “missing” (only 1 layer / Imageid now exists) and there will be a comment to indicate the merge has occurred and only 1 image layer now exists:

Output Without –squash

Output from Without --squash

Output With –squash (and comment showing merge)

Output from With --squashComment showing merge information

Advertisements
Docker for Windows -SwitchDaemon easily — May 3, 2018

Docker for Windows -SwitchDaemon easily

If you are using Docker for Windows and want to switch between Linux or Windows containers you can do this by right clicking the Docker “Whale” in the systray and selecting “Switch to Windows containers”:

Switch to Windows containers

….but no one likes clicking around do they!

There is an alternative way to do this which I use in my docker session demo’s which makes things so much easier and the switch is a lot quicker! In powershell, run the script below and it’ll switch from Linux to Windows containers and vice versa:

Linux Containers:

LinuxContainerDaemon

Run the SwitchDaemon script:

& 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon
Windows Containers:
WindowsContainerDaemon
and there you have it, a very simple but extremely useful snippet to switch between Linux and Windows containers,