Docker shipping images
Prerequisites
There should be two docker installed boxes. Here in my case I'm using mstr, node1 boxes on my GCP.
High level overview
Docker images can be build based on the project requirements, Development team prepared a image which need to be ship to remote hosts. This is one of the key requirement for containerized micro-service applications.
Docker shipping using docker save and docker load commands |
Step 1: In this post we will be creating a custom docker image name as 'dhanvi:1.0'.
Step 2. Save the custom image to a tar file and also tar.gz file (docker save).
Step 3. Ship the minimal size image file that is tar.gz file to a remote host (scp from mstr to node1).
Step 4. On the remote host load the docker image file using (docker load).
Step 5. List the docker images on the node1 and run the container.
Custom Image creation
Docker image save
Docker command CLI provides us to save a docker image to a user specified file using docker save command.
Save syntax:
docker image save IMAGENAME | IMAGE_ID > imagefile.tar or docker image save IMAGENAME |gzip > myimage_latest.tar.gzImage save example:
Let's take our newly build image 'dhanvi:1.0' to work with docker save command:
docker save dhanvi:1.0 > dhanvi1.0.tar docker image save dhanvi:1.0 |gzip > dhanvi1.0.tar.gz # or docker image save -o dhanvi_1.0.tar dhanvi:1.0 # Verify the image file sizes ls -lh
docker save command execution flow |
Shipping image Docker images we can ship the image to remote host box. The image shipping can be done either manually copying to a pen-drive from developer machine to testing machine. Alternatively you can use 'scp'(secure copy in Linux) command by providing user credentails. Here I've copied to /tmp location you can use as per your project requirement.
scp IMAGE.tar.gz user@rebothost:/tmp
Docker image load
docker load -i /tmp/dhanvi1.0.tar.gz or docker load --input /tmp/dhanvi1.0.tar.gz or docker load < /tmp/dhanvi1.0.tar.gz
Screenshot of docker load command execution
docker load command execution |
No comments:
Post a Comment