docker
containerization
AWS
DevOps
tutorial

How to create a new docker image from a running container on Amazon?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Creating a new Docker image from a running container on AWS uses the same Docker commands you would use anywhere else. The usual workflow is to identify the running container, commit it into a new image, tag that image, and optionally push it to a registry such as Amazon ECR.

This is useful for snapshots, debugging, or preserving a temporary container state. It is not the best long-term build strategy for reproducible deployments, but it can be practical when you need to capture a live container quickly.

Find the Running Container

Start by listing running containers on the EC2 instance or other host:

bash
docker ps

You might see output like this:

text
CONTAINER ID   IMAGE          COMMAND                  NAMES
abc123def456   myapp:latest   "dotnet MyApp.dll"      myapp-prod

The container ID or container name is what you will use for the snapshot.

Commit the Container to a New Image

Use docker commit to create a new image from the current container filesystem:

bash
docker commit myapp-prod myapp:snapshot

That creates a local image named myapp:snapshot. You can confirm it with:

bash
docker images

You can also attach a message to the commit:

bash
docker commit -m "Snapshot after emergency config fix" myapp-prod myapp:snapshot

This is a quick way to preserve the state after manual debugging or recovery work.

Tag the Image for Amazon ECR

If you want to store the image in AWS, tag it with your ECR repository URI:

bash
docker tag myapp:snapshot 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:snapshot

Then authenticate and push:

bash
aws ecr get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:snapshot ``` At that point the snapshot is available from ECR like any other Docker image. ## Understand What `docker commit` Really Captures `docker commit` saves the container filesystem state. That can include installed packages, modified configuration files, generated assets, and other in-container changes. What it does not give you is a clean, repeatable build recipe. The committed image contains the result of the changes, but not the reasoning or the exact build steps that produced them. That is why `docker commit` is best treated as a snapshot tool, not as the normal build pipeline. ## A Good Practical Workflow A reasonable emergency workflow is: 1. inspect and modify the running container 2. commit it so the state is not lost 3. test the committed image 4. move the real fix into a Dockerfile or deployment pipeline later This keeps short-term debugging flexible without turning manual container edits into permanent infrastructure practice. ## Security and Operational Concerns Be careful about what ends up inside the committed image. If the container contains temporary credentials, debug dumps, or ad hoc configuration files, the snapshot will preserve them too. That means you should inspect and clean sensitive data before pushing the image to ECR or sharing it with a team. ## Common Pitfalls - Treating `docker commit` as a long-term build process instead of a snapshot mechanism. - Forgetting to tag the image correctly before pushing to ECR. - Capturing secrets or temporary files inside the committed image. - Assuming the image documents the build steps that created it. - Failing to move the useful changes back into a Dockerfile later. ## Summary - On AWS, creating an image from a running container still uses ordinary Docker commands. - Use `docker commit` to snapshot the container state. - Tag the result for ECR and push it if you want to store it in AWS. - Treat committed images as temporary or investigative artifacts. - For repeatable builds, move the final change into version-controlled build definitions.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design