Search
Close this search box.

How to create a new AI docker image from a running container

how create new image From Container

Table of Contents

1. Introduction

Something tells me that you have been in situation when you wanted to save all the changes you did to currently running container. As you know container is image with writable layer on top. You may currently thinking that logically it is possible by simple make it read only and add on top of the stack. It is indeed possible. I will show you right now how to achieve that with Ollama docker image.

2. Example with ollama and codellama

Ollama is model provider and there is docker image on docker hub. This docker image does not contain any model files in it’s layers so after first startup and call for model it will download particular files.

2.1. Create fat docker image with codellama:7b model

In the below example you are pulling vanilla olama image and then by calling codellama:7b model you are triggering downloading necessary files inside container.

Next you obtain container ID and commit with new name and tag.

Once done you can use new image right away 🙂

				
					docker pull ollama/ollama
docker run -d --name ollama ollama/ollama
docker exec -it ollama ollama run codellama:7b

dockerContainerID=`docker ps --filter name=ollama -q`;

docker commit $dockerContainerID  toughcoding/ollama-codellama:7b

docker run -d  -p 11434:11434 --name ollama-codellama toughcoding/ollama-codellama:7b
docker exec -it ollama-codellama ollama run codellama:7b
				
			

3. Prepare for AMD64

Because I am running on MacOS it creates Arm64 version of image. To make it compatible with other platform you should download explicitly amd64 signatured version.

3.1. Pulling particular OS version image

				
					docker image pull ollama/ollama:0.1.27@sha256:0f278f2532971eeaf52a27c69455df785443e04bb5349bfa0de833facd6dce1a
				
			

3.2. Run container

				
					docker run -d --name ollama ollama/ollama:0.1.27@sha256:0f278f2532971eeaf52a27c69455df785443e04bb5349bfa0de833facd6dce1a
# run ollama with particular model to pull model into container
docker exec -it ollama ollama run codellama:7b
				
			

3.3. Get ID of running container

				
					dockerContainerID=`docker ps --filter name=ollama -q`;
				
			

3.4. Commit layer with model in place

				
					docker commit $dockerContainerID  toughcoding/ollama-codellama:7b
				
			

4. Final thoughts

Not everyone knows how to convert running container into separate image. In this tutorial you have learned how to achieved that with simple commands.

What will be your next project where you will be using explained technique?

Have a nice coding!

Follow me on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

Share the Post:

Enjoy Free Useful Amazing Content

Related Posts