How To Save And Load Docker Container On Rocky Linux 8.6

To save and load Docker container on Rocky Linux 8.6

Introduction

The Docker container allows us to separate applications from infrastructure, which makes it easier to develop, ship, and run software quickly. In addition, we can manage our infrastructure the same way we manage our applications.

Installation Procedure

Step 1: Check the OS version by using following commands

[root@linuxhelp ~]# cat /etc/os-release 
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

Step 2: Run the Docker image with Bash Shell by using the below command

[root@linuxhelp ~]# docker run -it ubuntu:latest /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
405f018f9d1d: Pull complete 
Digest: sha256:b6b83d3c331794420340093eb706a6f152d9c1fa51b262d9bf34594887c2c7ac
Status: Downloaded newer image for ubuntu:latest

Step 3: Create a directory by using the below command

root@e6a00b69c3b4:/# mkdir test

Step 4: Exit from the image by using the below command

root@e6a00b69c3b4:/# exit
exit

Step 5: List the container by using the Docker command

[root@linuxhelp ~]# docker ps -a
CONTAINER ID   IMAGE           COMMAND       CREATED          STATUS                      PORTS     NAMES
e6a00b69c3b4   ubuntu:latest   "/bin/bash"   58 seconds ago   Exited (0) 18 seconds ago             awesome_robinson

Step 6: Start the Container by using the below command

[root@linuxhelp ~]# docker start e6a00b69c3b4
e6a00b69c3b4

Step 7: Commit the Docker container by using the below command

[root@linuxhelp ~]# docker commit awesome_robinson ubuntu:test
sha256:bad79cc8ac0bde6107074c12ec03d5810cc9ff33bacd4ed17cc89b6480d3840d

Step 8: Stop the container by using the below command

[root@linuxhelp ~]# docker stop awesome_robinson
awesome_robinson

Step 9: Save the Docker container as tar file by using the below command

[root@linuxhelp ~]# docker save ubuntu:test > ubuntu.test.tar

Step 10: List the saved file by using the below command

[root@linuxhelp ~]# ls -la
-rw-r--r--.  1 root root 80356864 Jul 26 17:12 ubuntu.test.tar

Step 11: List the Docker images by using the below command

[root@linuxhelp ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED              SIZE
ubuntu       test      bad79cc8ac0b   About a minute ago   77.8MB
ubuntu       latest    27941809078c   7 weeks ago          77.8MB

Step 12: Remove the images by using container ID by using the below command

[root@linuxhelp ~]# docker rmi bad79cc8ac0b
Untagged: ubuntu:test
Deleted: sha256:bad79cc8ac0bde6107074c12ec03d5810cc9ff33bacd4ed17cc89b6480d3840d
Deleted: sha256:3f0e5ea4b306ed14ec7eb62a4ba02f67fab33342abc43f32b55e359b7c30c12b

Step 13: Load the saved container by using the below command

[root@linuxhelp ~]# docker load < ubuntu.test.tar 
937aaa21edb2: Loading layer  3.584kB/3.584kB
Loaded image: ubuntu:test

Step 14: Run the loaded Docker image with Bash Shell by using the below command

[root@linuxhelp ~]# docker run -it ubuntu:test /bin/bash

Step 15: List the created file by using the below command

root@1f3395c1e71a:/# ls -la
total 0
drwxr-xr-x.   1 root root   6 Jul 26 21:15 .
drwxr-xr-x.   1 root root   6 Jul 26 21:15 ..
-rwxr-xr-x.   1 root root   0 Jul 26 21:15 .dockerenv
lrwxrwxrwx.   1 root root   7 May 31 15:42 bin -> usr/bin
drwxr-xr-x.   2 root root   6 Apr 18 10:28 boot
drwxr-xr-x.   5 root root 360 Jul 26 21:15 dev
drwxr-xr-x.   1 root root  66 Jul 26 21:15 etc
drwxr-xr-x.   2 root root   6 Apr 18 10:28 home
lrwxrwxrwx.   1 root root   7 May 31 15:42 lib -> usr/lib
lrwxrwxrwx.   1 root root   9 May 31 15:42 lib32 -> usr/lib32
lrwxrwxrwx.   1 root root   9 May 31 15:42 lib64 -> usr/lib64
lrwxrwxrwx.   1 root root  10 May 31 15:42 libx32 -> usr/libx32
drwxr-xr-x.   2 root root   6 May 31 15:42 media

drwxr-xr-x.   2 root root   6 May 31 15:42 mnt
drwxr-xr-x.   2 root root   6 May 31 15:42 opt
dr-xr-xr-x. 264 root root   0 Jul 26 21:15 proc
drwx------.   1 root root  27 Jul 26 21:10 root
drwxr-xr-x.   5 root root  46 May 31 15:45 run
lrwxrwxrwx.   1 root root   8 May 31 15:42 sbin -> usr/sbin
drwxr-xr-x.   2 root root   6 May 31 15:42 srv
dr-xr-xr-x.  13 root root   0 Jun 24 02:31 sys
drwxr-xr-x.   2 root root   6 Jul 26 21:10 test
drwxrwxrwt.   2 root root   6 May 31 15:45 tmp
drwxr-xr-x.  14 root root 160 May 31 15:42 usr
drwxr-xr-x.  11 root root 139 May 31 15:45 var

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to save and load Docker container on Rocky Linux 8.6. Your feedback is much welcome.

Tag : Linux Docker
FAQ
Q
How to get the name of the existing container?
A
To get the name of the existing container use "docker ps".
Q
How to run commands to the container?
A
To run commands to the container use the "docker exec -it " command
Q
How to load the Docker container?
A
To load the Docker container use the command "docker load < filename.tar".
Q
How to save the Docker container?
A
To save the Docker container use the command "docker save containername > filename.tar".
Q
How to get the Bash of the container?
A
To get the Bash of the container use the command "docker exec -it /bin/bash".