Create a Docker Image From Container

Ticker

6/recent/ticker-posts

Create a Docker Image From Container

 Question: One of the Nautilus developer was working to test new changes on a container. He wants to keep a backup of his changes to the container. A new request has been raised for the DevOps team to create a new image from this container. Below are more details about it:

a. Create an image media:datacenter on Application Server 2 from a container ubuntu_latest that is running on same server.

Please Note :-  Perform the below commands based on your question server,  user name & other details that might differ. So please read the task carefully before executing it. 
All the Best 👍

Solution:  

 1. Login on app server  ( Refer your task) & Switch to  root user

thor@jump_host ~$  ssh steve@stapp02

The authenticity of host 'stapp02 (172.16.238.11)' can't be established.

ECDSA key fingerprint is SHA256:VqDmFflIgUQEQ0mKslpNubcER8NdSK9rnbP0q4HFnos.

ECDSA key fingerprint is MD5:ef:78:a5:4c:c0:cc:90:3e:dd:ea:f3:72:19:61:28:d9.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'stapp02,172.16.238.11' (ECDSA) to the list of known hosts.

steve@stapp02's password:

[steve@stapp02 ~]$ sudo su -

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

[sudo] password for steve:

[root@stapp02 ~]#

 2. Check existing docker container ubuntu_latest running status 

[root@stapp02 ~]# docker ps

CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS         PORTS     NAMES

e44ada0bb828   ubuntu    "bash"    2 minutes ago   Up 2 minutes             ubuntu_latest

[root@stapp02 ~]#


 3. Look at the list of images on your system

[root@stapp02 ~]# docker images

REPOSITORY   TAG       IMAGE ID       CREATED       SIZE

ubuntu       latest    1318b700e415   12 days ago   72.8MB

[root@stapp02 ~]#

 4. Create a new image from this container as per the task 

[root@stapp02 ~]# docker commit ubuntu_latest media:datacenter

sha256:262c15389ffd0c8be00efa9b4364e678f6d5c337dd0658382d85cea77bd72a37

[root@stapp02 ~]#

5. Validate the task by running 

[root@stapp02 ~]# docker images

REPOSITORY   TAG          IMAGE ID       CREATED          SIZE

media        datacenter   262c15389ffd   13 seconds ago   103MB

ubuntu       latest       1318b700e415   12 days ago      72.8MB

[root@stapp02 ~]#


6.  Click on Finish & Confirm to complete the task successfully

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , please go through and share your comments. Like and share the knowledge










Post a Comment

2 Comments

  1. Hi,

    I'm curious, why is the new image (demo:datacenter) bigger than original (ubuntu_latest)?

    [root@stapp03 ~]# docker image ls
    REPOSITORY TAG IMAGE ID CREATED SIZE
    demo datacenter 5b54d28983a3 5 seconds ago 103MB
    ubuntu latest 1318b700e415 11 days ago 72.8MB

    ReplyDelete
    Replies
    1. Hi Dannie,

      The more layers an image have the larger the result size is.

      The increased size can have multiple reasons .

      You can easily check the difference and probably the reason for the inflated image size with the docker diff {container_name}, which shows you exactly the differences.

      Delete

Latest Posts

Security Group Variable Setup Using Terraform Kodekloud Engineer Task Success