DEV Community

Cover image for 3.Create a Docker Image From Container
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

3.Create a Docker Image From Container

Task Information

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 official:nautilus on Application Server 1 from a container ubuntu_latest that is running on same server.

Task Solutions

Part 1: Lab Step-by-Step Guidelines

✅ Task

On Application Server 1 (stapp01), create a new Docker image:

official:nautilus

from the running container:

ubuntu_latest

Step 1: Login to the Jump Host

ssh thor@jump-host

# Password:

mjolnir123
Enter fullscreen mode Exit fullscreen mode

Step 2: SSH into App Server 1

ssh tony@stapp01
# Password:
Ir0nM@n
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify the container is running

Check that container ubuntu_latest exists:

docker ps
Enter fullscreen mode Exit fullscreen mode

You should see:

ubuntu_latest

Step 4: Create image from the container

Use docker commit:

docker commit ubuntu_latest official:nautilus
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify the image

Check image list:

docker images
Enter fullscreen mode Exit fullscreen mode

You should see:

official nautilus


Part 2: Simple Step-by-Step Explanation (Beginner Friendly)

What is happening in this lab?

A developer made changes inside a running container and wants to save those changes as a new reusable image.

Think of it like:

Container = running machine with changes
Image = saved snapshot/template
What does docker commit do?
docker commit ubuntu_latest official:nautilus

This means:

“Take the current state of container ubuntu_latest and save it as a new image named official:nautilus.”

Breakdown
docker commit → create image from container
ubuntu_latest → source container
official:nautilus → new image name and tag

Why use this?

If someone installed packages or changed files inside the container, docker commit preserves those changes into a new image.

Then later you can run:

docker run official:nautilus

and get the saved version.

⚠️ Common Mistakes

❌ Mistake 1: Using image name instead of container name

Wrong:

docker commit ubuntu official:nautilus

Correct:

docker commit ubuntu_latest official:nautilus

Use the container name, not the base image name.

❌ Mistake 2: Running on wrong server

Do this on:

stapp01

❌ Mistake 3: Typing image tag incorrectly

Correct:

official:nautilus


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)