How to Export and Import Docker Container on Rocky Linux 8.6
- 00:35 cat /etc/os-release
- 00:58 docker pull ubuntu
- 01:16 docker images
- 01:45 docker run -dit ubuntu
- 01:58 docker ps
- 02:57 docker exec -it stoic_lichterman /bin/bash
- 03:14 apt update
- 04:10 apt install tree -y
- 04:42 docker ps
- 05:17 docker export --output="tree.tar" stoic_lichterman
- 06:15 docker import tree.tar
- 07:43 docker images
- 08:21 docker run -it 8ec36daac216 /bin/bash
- 08:58 apt list --installed |grep tree
To Export and Import Docker Container on Rocky Linux 8.6
Introduction:
Docker is a platform as a service that delivers software in containers using OS-level virtualization, which enables you to build, test, and deploy applications quickly and easily.
Installation Procedure:
Step 1: Check the OS version by using the below command
[root@localhost ~]# 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: Pull the Ubuntu Docker Image from Docker Hub by using the below command
[root@localhost ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
d19f32bd9e41: Pull complete
Digest: sha256:34fea4f31bf187bc915536831fd0afc9d214755bf700b5cdb1336c82516d154e
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
Step 3: List the Docker Images by using the below command
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest df5de72bdb3b 5 days ago 77.8MB
hello-world latest feb5d9fea6a5 10 months ago 13.3kB
Step 4: Run a Container from Ubuntu Docker Image by using the below command
[root@localhost ~]# docker run -dit ubuntu
def73521f6034b0e951d57591cd459d5091b03f628ae8040b023c35c69a881bd
Step 5: Check the Running Containers by using the below command
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
def73521f603 ubuntu "bash" 14 seconds ago Up 11 seconds stoic_lichterman
Step 6: Login to the Container Shell by using the below command
[root@localhost ~]# docker exec -it stoic_lichterman /bin/bash
Step 7: Update the APT source List
root@def73521f603:/# apt update
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Get:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages [1792 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy/restricted amd64 Packages [164 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 Packages [266 kB]
Get:8 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages [17.5 MB]
0% [8 Packages 17.0 MB/17.5 MB 97%] 290 kB/s 1s
0% [8 Packages 17.2 MB/17.5 MB 99%] 290 kB/s 0s
Reading package lists... Done
E: Release file for http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease is not valid yet (invalid for another 43min 44s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease is not valid yet (invalid for another 43min 50s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease is not valid yet (invalid for another 44min 10s). Updates for this repository will not be applied.
Step 8: Install tree Package for testing purpose by using the below command
root@def73521f603:/# apt install tree -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
tree
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 47.9 kB of archives.
After this operation, 116 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 tree amd64 2.0.2-1 [47.9 kB]
Fetched 47.9 kB in 1s (45.1 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package tree.
(Reading database ... 4395 files and directories currently installed.)
Preparing to unpack .../tree_2.0.2-1_amd64.deb ...
Unpacking tree (2.0.2-1) ...
Setting up tree (2.0.2-1) ...
Step 9: Exit from the Container by using the below command
root@def73521f603:/# exit
exit
Step 10: Check the Running Containers by using the below command
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
def73521f603 ubuntu "bash" 3 minutes ago Up 3 minutes stoic_lichterman
Step 11: Export the Running Container as tar file by using the below command
[root@localhost ~]# docker export --output="tree.tar" stoic_lichterman
Step 12: List the exported Image by using the below command
[root@localhost ~]# ls -la
total 110416
dr-xr-x---. 16 root root 4096 Aug 7 14:05 .
dr-xr-xr-x. 17 root root 224 Jun 27 08:39 ..
-rw-------. 1 root root 1204 Jun 27 08:48 anaconda-ks.cfg
-rw-------. 1 root root 115 Jun 27 03:23 .bash_history
-rw-r--r--. 1 root root 18 Mar 14 2021 .bash_logout
-rw-r--r--. 1 root root 176 Mar 14 2021 .bash_profile
-rw-r--r--. 1 root root 129 Mar 14 2021 .tcshrc
drwxr-xr-x. 2 root root 6 Jun 27 08:50 Templates
-rw-------. 1 root root 113016832 Aug 7 14:05 tree.tar
drwxr-xr-x. 2 root root 6 Jun 27 08:50 Videos
-rw-------. 1 root root 134 Jul 22 02:39 .Xauthority
Step 13: Import the Exported Container, The Exported Container is imported as Docker Image then need to run the Containers from the Image by using the below command
[root@localhost ~]# docker import tree.tar
sha256:8ec36daac21660ae60192578d850b4dd681ea6addf99106fec107d4df1b58e52
Step 14: List the Docker Images by using the below command
root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 8ec36daac216 22 seconds ago 110MB
ubuntu latest df5de72bdb3b 5 days ago 77.8MB
hello-world latest feb5d9fea6a5 10 months ago 13.3kB
Step 15: Run a Container from the Imported Docker Image by using the below command
[root@localhost ~]# docker run -it 8ec36daac216 /bin/bash
Step 16: Check the Package installed before exporting by using the below command
root@6c5b9045e4cd:/# apt list --installed |grep tree
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
tree/jammy,now 2.0.2-1 amd64 [installed]
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to Export and Import Docker Container on Rocky Linux 8.6. Your feedback is much welcome.
Comments ( 0 )
No comments available