Creating your own images

With the mechanism we just saw, we can change everything inside our containers. But what if you want to make sure that your colleagues, partners, or customers get exactly those same modifications without the need to get the my-scripts override right? Or what if you need some DLLs or other files inside your container and want to deliver them as part of your own image? The answer to that is building your own image, which, fortunately, is very easy as well.

Docker has a layering concept that makes an image a stack of layers. All you need to do is put your own layer on top of the standard image. You can do that by using a Dockerfile, which needs a reference to the standard image you want to extend and then the actions you want to take. Let's say you want to place some DLLs stored in c:cdlls into the image Add-ins folder and put your own AdditionalSetup.ps1 script from the c:coverride folder into the c: un image folder. Your Dockerfile would look as follows, stored in the c:c folder:

FROM mcr.microsoft.com/businesscentral/sandbox
COPY ["./dlls/*", "c:/Program Files/Microsoft Dynamics NAV/150/Service/Add-ins/"]
COPY ./override/AdditionalSetup.ps1 c:/run/

To build this image, you need to run the docker build command in c:c and give your image a name using the -t parameter:

docker build -t myimage

The result will look something like the following:

Sending build context to Docker daemon 7.168kB
Step 1/3 : FROM mcr.microsoft.com/businesscentral/sandbox
---> 20f72db6c9a9
Step 2/3 : COPY ./dlls/* c:/Program Files/Microsoft Dynamics NAV/150/Service/Add-ins/
---> f202642914a9
Step 3/3 : COPY ./override/AdditionalSetup.ps1 c:/run/
---> 1164c1273517
Removing intermediate container e9070e72cbaa
Successfully built 1164c1273517
Successfully tagged myimage:latest

With that in place, you can use your image like any other image:

docker run -e accept_eula=y myimage

The way to share this image with others is via a Docker repository. For an image that's been built on top of the official Microsoft image, this will be done with a private repository. How to set that up is beyond the scope of this book, but https://docs.docker.com/registry/ is a good starting point if you want to learn more.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.72.224