0% found this document useful (0 votes)
13 views9 pages

Managing Docker Images

This lab provides a comprehensive guide on managing Docker images, including searching, pulling, saving, loading, committing, exporting, importing, tagging, and cleaning up images. Participants will execute various Docker commands to manipulate images and containers, ensuring they understand the processes involved. The lab emphasizes practical execution of commands to reinforce learning outcomes related to Docker image management.

Uploaded by

harshagv1994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

Managing Docker Images

This lab provides a comprehensive guide on managing Docker images, including searching, pulling, saving, loading, committing, exporting, importing, tagging, and cleaning up images. Participants will execute various Docker commands to manipulate images and containers, ensuring they understand the processes involved. The lab emphasizes practical execution of commands to reinforce learning outcomes related to Docker image management.

Uploaded by

harshagv1994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Lab: Managing Docker Images

Introduction
In this lab, you will learn how to search, pull, push and remove container images from the
docker registry.
Objective:

 Search Image
 Pull Image
 Save/Load image
 Commit container state
 Export/Import Image
 Tag Image
 Cleanup

1 Ensure that you have logged-in as root user with password as linux.

1.1 Let us list the images, by executing the below command.

# docker image ls

Output:

1.2 Let us search image, by executing the below command.

# docker search alpine

Output:
1.3 Let us search image by applying the filter, by executing the below command.

# docker search alpine --filter=stars=100

Output:

1.4 Let us pull an image, by executing the below command.

# docker image pull alpine

Output:

Note: By default, pull will get the Official latest image from the Docker hub.

1.5 Let us list the images, by executing the below command.

# docker image ls

Output:

1.6 Let us pull an image from a specific repository, by executing the below command.

# docker image pull docker.io/alpine/git

Output:
1.7 Let us list the images, by executing the below command.

# docker image ls

Output:

1.8 Let us inspect the image, by executing the below command.

# docker image inspect alpine

Output:

1.9 Let us save the image, by executing the below command.

# docker image save alpine -o alpine_backup.tar


1.10 Let us list the backup file, by executing the below command.

# ls -l alpine_backup.tar

Output:

1.11 Let us list the contents of the Tar ball, by executing the below command.

# tar -tvf alpine_backup.tar

Output:

1.12 Let us remove the existing image to test loading the backup image, by executing the
below command.
# docker image rm alpine

Output:

1.13 Let us list the images, by executing the below command.

# docker image ls

Output:

1.14 Let us load an image from the tar archive, by executing the below command.

# docker image load --input alpine_backup.tar

Output:
1.15 Let us list the images, by executing the below command.

# docker image ls

Output:

1.16 Let us check the history of an image, by executing the below command.

# docker image history alpine

Output:

Docker Container Commit:

2.1 Let us run a container, by executing the below command.

# docker container run --name server01 -dit centos:7

Output:

2.2 Let us attach to the container to make few changes, by executing the below command.

# docker container attach server01


# yum -y install httpd
# touch /testFile
Press “ctrl+p ctrl+q” to come out

Output:
2.3 Let us commit the container state as a new image, by executing the below command.

# docker container commit server01 centos:httpd

Output:

2.4 Let us list the images, by executing the below command.

# docker image ls

Output:

2.5 Let us create a container out of new image, by executing the below command.

# docker container run --name server02 -dit centos:httpd


Output:

2.6 Let us verify the content of a newly created container, by executing the below command.

# docker container exec server02 ls -l /testFile


Output:
# docker container exec server02 rpm -q httpd
Output:

2.7 Let us check the difference made inside a container before the commit, by executing the
below command.
# docker container diff server01 | grep testFile
Output:

3 Docker Container Export and Image Import


3.1 Let us export a container state to capture the state of a container as a tar ball, by executing
the below command.
# docker container export server02 > server02_latest.tar
3.2 Let us list the file, by executing the below command.

# ls -lh server02_latest.tar

Output:

3.3 Let us import the tarball as an image, by executing the below command.

# docker image import server02_latest.tar centos:server02

Output:

3.4 Let us list the images, by executing the below command.

# docker image ls
Output:

3.5 Let us remove a specific image, by executing the below command.

# docker image rm docker.io/alpine/git

Output:

3.6 Let us list the images, by executing the below command.

# docker image ls

Output:

3.7 Let us cleanup unused images, by executing the below command.

# docker image prune -a -f

Output:
3.8 Let us list the images, by executing the below command.

# docker image ls

Output:

Cleanup

4.1 Let us cleanup, by executing the below command.

# docker container rm `docker container ls -a -q` -f

# docker image rm `docker image ls -q` -f

You might also like