HOW TO SAVE, LOAD AND TRANSFER DOCKER IMAGE — with Real Job Scenario/DevOps ticket

“Transferring and Loading Docker Images Between Servers — A DevOps Guide”

GABRIEL OKOM
4 min readOct 5, 2023
Docker Image build process

I was recently asked to load a copy of a docker image into a different server from the current server it is running on. I’d like to share with you how I was able to get this done in few easy steps.

In the world of DevOps and containerization, transferring Docker images between servers is a common task/ticket. In this post, we’ll explore how to save a Docker image on one server, transfer it to another, and then load it with the same name and tag.

NOTE:

These are fictional characters aimed for better understanding and illustration of the processes.

We’ll use two servers for this purpose: App Server 1 (tony@172.16.238.10) and App Server 3 (banner@172.16.238.12).

Objectives:

  1. How to transfer Docker images between servers.
  2. Introduce a relatable real-world scenario, this approach makes the content more engaging and relatable.
  3. Give best practices for secure image transfer and deployment.

Prerequisites:

  1. Basic Docker Knowledge: such as images, containers, and Docker commands.
  2. Access to Servers: To follow the steps in the post, have access to at least two servers (in this case, App Server 1 and App Server 3) via SSH or another method.
  3. Docker Installed: Docker should be installed and configured on both servers. Docker should be up and running.
  4. Familiarity with SSH; and Sudo Access.

Job Scenario:

“One of the DevOps team members was working on to create a new custom docker image on App Server 1 in Stratos DC. He is done with his changes and image is saved on same server with name official:datacenter. Recently a requirement has been raised by a team to use that image for testing, but the team wants to test the same on App Server 3. So we need to provide them that image on App Server 3 in Stratos DC.

a. On App Server 1 save the image official:datacenter in an archive.

b. Transfer the image archive to App Server 3.

c. Load that image archive on App Server 3 with same name and tag which was used on App Server 1.”

Solution:

Step 1: Saving the Docker Image on App Server 1

ssh tony@172.16.238.10

Let’s assume we have a Docker image named official:datacenter on App Server 1. and have already confirmed the image availability by running

docker images

To save this image as an archive, we'll use the following command:

docker save -o official_datacenter.tar official:datacenter

This command saves the Docker image as an archive file named official_datacenter.tar.

Step 2: Transferring the Image Archive to App Server 3

To transfer the image archive to App Server 3, we can use scp, a secure copy tool. Replace user with your username on App Server 3 and /path/to/destination/ with the destination directory path on App Server 3.

scp official_datacenter.tar banner@172.16.238.12:/home/banner

Step 3: Loading the Docker Image on App Server 3

On App Server 3, we can now load the Docker image from the archive with the same name and tag as it had on App Server 1:

ssh banner@172.16.238.12
docker load -i official_datacenter.tar

This command loads the Docker image, and it will be available on App Server 3 for testing.

Confirming the Loaded Image

To confirm that the Docker image has been successfully loaded on App Server 3, you can use the docker images command:

docker images

This will list all Docker images on the server, including the newly loaded official:datacenter image.

Security Recommendations and Tips

  1. Secure Transfer: When transferring Docker images between servers, use secure methods like SSH (as demonstrated with scp) to protect your data in transit.
  2. Image Signing: Consider signing your Docker images with Docker Content Trust to ensure the integrity and authenticity of images during transfer and loading.
  3. Network Isolation: Keep servers and containers in separate network segments to minimize exposure. Use network security groups or firewalls to restrict access to Docker ports.
  4. Regular Updates: Keep your Docker software and operating systems up to date with security patches to mitigate potential vulnerabilities.
  5. Least Privilege: Limit permissions and access rights to only those who need them. Use strong, unique passwords for server access.
  6. Container Scanning: Employ container scanning tools to identify vulnerabilities in your Docker images before deployment.
  7. Logging and Monitoring: Implement robust logging and monitoring solutions to detect and respond to suspicious activities.

By following these security recommendations and tips, you can enhance the security of your Docker environment and ensure safe image transfer and deployment.

#docker #containers #kubernetes #dockerimages #orchestration #save #load #GabrielOkom #devops

--

--

GABRIEL OKOM
GABRIEL OKOM

Written by GABRIEL OKOM

MSc Cyber Security and Computer Forensics | Certified DevOps Engineer

Responses (1)