MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Docker Lab & Assignment – Creating an Image

Hereโ€™s a detailed Tutorial and Lab Guide for the listed Docker commands, focused on practical usage, explanations, and step-by-step labs with Ubuntu + git + apache2 as the image base. The guide is split into two labs as you requested, plus explanations and examples for every command.


Docker Image and Image Management: Tutorial & Lab Guide


Table of Contents

  1. Introduction
  2. Lab 1: Creating Docker Images Using a Container (commit/export/import)
  3. Lab 2: Creating Docker Images Using a Dockerfile (build)
  4. Image Management Commands: Tutorial & Examples
    • images
    • history
    • inspect
    • rmi
    • tag
    • export
    • import
    • save
    • load
    • commit

Introduction

Docker images are the blueprint for containers, holding everything needed to run an applicationโ€”code, dependencies, and runtime. Managing images efficiently is critical for any container workflow. This guide will help you understand not only how to build images, but also how to manage, tag, save, and load them.


Lab 1: Creating Docker Images Using a Container

Objective

Create a custom Docker image based on Ubuntu by launching a container, installing git and apache2, and committing the containerโ€™s state as a new image.

Steps

1. Pull the Ubuntu base image

docker pull ubuntu:latest
Code language: CSS (css)

2. Run a container interactively

docker run -it --name myubuntu ubuntu:latest
Code language: CSS (css)

3. Install git and apache2 inside the container

Inside the container shell:

apt-get update
apt-get install -y git apache2
exit
Code language: JavaScript (javascript)

4. Commit the container to a new image

docker commit myubuntu ubuntu-git-apache2:v1
Code language: CSS (css)

5. Verify the image

docker images

You should see ubuntu-git-apache2 listed.

6. Tag your image for clarity

docker tag ubuntu-git-apache2:v1 myrepo/ubuntu-git-apache2:lab1

7. (Optional) Run a container from your new image

docker run -it myrepo/ubuntu-git-apache2:lab1 bash

Lab 2: Creating Docker Images Using a Dockerfile

Objective

Create a Docker image using a Dockerfile that sets up Ubuntu with git and apache2.

Steps

1. Create a new directory for your Dockerfile

mkdir dockerfile-lab
cd dockerfile-lab

2. Create the Dockerfile

# Dockerfile
FROM ubuntu:latest

RUN apt-get update && \
    apt-get install -y git apache2 && \
    apt-get clean

CMD ["/bin/bash"]
Code language: CSS (css)

Save this as Dockerfile.

3. Build the image

docker build -t ubuntu-git-apache2:dockerfile .
Code language: CSS (css)

4. List the images

docker images

5. Run the new image

docker run -it ubuntu-git-apache2:dockerfile
Code language: CSS (css)

Image and Container Management Commands: Explanations & Examples

Below are the required commands, with clear explanations and hands-on examples using the images created in Labs 1 and 2.


1. images โ€” List Images

Usage:

docker images

What it does:
Lists all Docker images present locally.


2. history โ€” Show Image History

Usage:

docker history ubuntu-git-apache2:dockerfile
Code language: CSS (css)

What it does:
Displays the history of an imageโ€”each layer and its command.


3. inspect โ€” Inspect Docker Object

Usage:

docker inspect ubuntu-git-apache2:dockerfile
Code language: CSS (css)

What it does:
Gives detailed low-level JSON information about an image or container.


4. rmi โ€” Remove Image(s)

Usage:

docker rmi ubuntu-git-apache2:dockerfile
Code language: CSS (css)

What it does:
Removes a specified Docker image. (Stop running containers first.)


5. tag โ€” Tag Images

Usage:

docker tag ubuntu-git-apache2:dockerfile myrepo/ubuntu-git-apache2:prod

What it does:
Creates a new tag pointing to the same image (useful for versioning).


6. export โ€” Export Container Filesystem

Usage:

docker export myubuntu > myubuntu.tar
Code language: JavaScript (javascript)

What it does:
Exports the filesystem of a container as a tar archive (no history/layers).


7. import โ€” Import a Tarball as Image

Usage:

cat myubuntu.tar | docker import - myimported/ubuntu-git-apache2:v2
Code language: JavaScript (javascript)

What it does:
Creates an image from a tarball (reverse of export, but history lost).


8. save โ€” Save Image(s) to Tar Archive

Usage:

docker save -o ubuntu-git-apache2-lab2.tar ubuntu-git-apache2:dockerfile
Code language: CSS (css)

What it does:
Saves one or more images to a tar archive (preserves history/layers).


9. load โ€” Load Image(s) from Tar Archive

Usage:

docker load -i ubuntu-git-apache2-lab2.tar
Code language: CSS (css)

What it does:
Loads an image (including all tags and layers) from a tar archive created with docker save.


10. commit โ€” Create Image from Container

Usage:

docker commit myubuntu myrepo/ubuntu-git-apache2:manual

What it does:
Creates a new image from a containerโ€™s current state.


Full Example: End-to-End Workflow

  1. Start with Ubuntu, install software in a container:
    docker run -it --name ub-test ubuntu
    apt-get update && apt-get install -y git apache2
    exit
  2. Commit the container as an image:
    docker commit ub-test ub-git-apache:manual
  3. Save and Load the image:
    docker save -o ub-git-apache.tar ub-git-apache:manual
    docker load -i ub-git-apache.tar
  4. Export/Import container as image:
    docker export ub-test > ub-test.tar cat ub-test.tar
    docker import - ub-git-apache:imported
  5. Build image via Dockerfile:
    • Create Dockerfile as shown above.
    • Build: docker build -t ub-git-apache:dockerfile .
  6. Tag, Inspect, Remove:
    docker tag ub-git-apache:dockerfile myrepo/ub-git-apache:prod
    docker inspect myrepo/ub-git-apache:prod
    docker rmi myrepo/ub-git-apache:prod
  7. List Images, View History: docker images docker history ub-git-apache:dockerfile

Conclusion

You now have hands-on experience in:

  • Building Docker images both from containers and Dockerfiles.
  • Managing, saving, loading, and distributing Docker images.
  • Using all essential Docker image management commands with practical Ubuntu+git+apache2 examples.


Reference

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Docker commands Guide – docker build with examples

Hereโ€™s a complete tutorial on docker build, explaining what it does, examples, and use cases. What is docker build? docker build is a Docker command used to…

Read More

Docker Assignment

How to submit assignment? Write Ansswer for the following questions and submit answer at Debug.school as new post for each questions 1. What is Docker and why…

Read More

Interview Questions & Answers for Docker and Containers

Container What is a Container? What is it used for? How are containers different from virtual machines (VMs)? In which scenarios would you use containers and in…

Read More

Docker Interview Questions and Answer Part – 1

What happens when you run docker run hello-world? How do you run a container? What do you see when you run docker ps? What docker commit does? when will you use…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

This page collects sample Dockerfiles that build an Ubuntu-based Apache image and show how CMD, ENTRYPOINT, EXPOSE, ARG, ENV, COPY and USER behave. Below the examples you…

Read More

Docker Training Agenda: A Hands-On Learning Path from Containers to Registries and Networking

This revised Docker training agenda turns the original outline into a practical, modern learning path for beginners and early-career DevOps engineers. It maps each module to hands-on outcomes, core commands, and common implementation decisions.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x